package com.xinchuang.service.impl;

import cn.hutool.core.util.ObjectUtil;
import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.ExcelWriter;
import com.alibaba.excel.write.metadata.WriteSheet;
import com.alibaba.excel.write.metadata.fill.FillConfig;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xinchuang.comment.KeyWord;
import com.xinchuang.comment.R;
import com.xinchuang.domain.entity.DictTable;
import com.xinchuang.domain.entity.TestModelParam;
import com.xinchuang.domain.vo.*;
import com.xinchuang.entity.*;
import com.xinchuang.mapper.*;
import com.xinchuang.service.*;
import com.xinchuang.utils.BigdecimalUtil;
import com.xinchuang.utils.DateUtils;
import com.xinchuang.utils.ExcelUtil;
import com.xinchuang.utils.MyUtils;
import org.apache.commons.compress.utils.Lists;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.ss.util.RegionUtil;
import org.apache.poi.xssf.usermodel.*;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.TransactionStatus;
import org.springframework.transaction.support.DefaultTransactionDefinition;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.*;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;


@Service
public class DesignChangeModServiceImpl implements DesignChangeModService {
    @Autowired
    private IOuterDesignChangesService iOuterDesignChangesService;

    @Autowired
    private IOuterDesignChangesDetailService iOuterDesignChangesDetailService;

    @Autowired
    private IOuterDesignChangePriceService iOuterDesignChangePriceService;

    @Autowired
    private OuterDesignChangesMapper outerDesignChangesMapper;

    @Autowired
    private OuterDesignChangePriceMapper outerDesignChangePriceMapper;

    @Autowired
    private OuterDesignChangesDetailMapper outerDesignChangesDetailMapper;

    @Autowired
    private IInnerDesignChangePriceService priceService;

    @Autowired
    private IInnerDesignChangesDetailService detailService;

    @Autowired
    private IInnerDesignChangesService changesService;

    @Autowired
    private TestModelParamMapper modelParamMapper;

    @Autowired
    private PlatformTransactionManager transactionManager;

    @Resource
    private KeyWord keyWord;

    @Autowired
    private IMoldSelectionService iMoldSelectionService;

    @Autowired
    private InnerDesignChangesChangeMapper innerDesignChangesChangeMapper;

    @Autowired
    private OuterDesignChangesChangeMapper outerDesignChangesChangeMapper;

    @Autowired
    private DictTableMapper dictTableMapper;

    @Override
    public String getProjectProducts(JSONObject jsonObject) {
        //解析获取选模表Id
        String moldSelectionId = jsonObject.getString("moldSelectionId");
        List<TestModelParam> modelParams = modelParamMapper.selectList(new LambdaQueryWrapper<TestModelParam>().eq(TestModelParam::getMoldSelectionId, moldSelectionId).orderByAsc(TestModelParam::getMoldId));
        List<ModelParamVo> dataList = new ArrayList<>();
        JSONObject json = new JSONObject();
        //复制需要输出的属性
        for (TestModelParam modelParam : modelParams
        ) {
            ModelParamVo temp = new ModelParamVo();
            BeanUtils.copyProperties(modelParam, temp);
            dataList.add(temp);
        }
        json.put("dataList", dataList);
        return JSON.toJSONString(R.data(json), SerializerFeature.WriteNullNumberAsZero, SerializerFeature.WriteNullListAsEmpty, SerializerFeature.WriteNullStringAsEmpty, SerializerFeature.WriteNullBooleanAsFalse);
    }

    @Override
    public String getInnerDesignChangeDetail(JSONObject jsonObject) {
        //jsonobject解析获取选模表Id
        String moldSelectionId = jsonObject.getString("moldSelectionId");
        //jsonobject解析获取是否审批
        String isApprove = jsonObject.getString("isApprove");
        List<InnerDesignChangesDetail> innerDesignChangesDetails = detailService.list(
                new LambdaQueryWrapper<InnerDesignChangesDetail>()
                        .eq(InnerDesignChangesDetail::getMoldSelectionId, moldSelectionId)
                        .eq(StringUtils.isNotEmpty(isApprove), InnerDesignChangesDetail::getIsApprove, isApprove)
                        .orderByAsc(InnerDesignChangesDetail::getMoldId));
        InnerDesignChanges changes = changesService.getOne(
                new LambdaQueryWrapper<InnerDesignChanges>()
                        .eq(InnerDesignChanges::getMoldSelectionId, moldSelectionId));
        List<InnerDetailsVo> innerDetailsVos = setDetailsValues(innerDesignChangesDetails);
        JSONArray array = JSONArray.parseArray(JSON.toJSONString(innerDetailsVos));
        JSONObject json = new JSONObject();
        if (changes != null) json.put("totalFee", changes.getTotalPrice());
        if (innerDetailsVos.size() != 0) json.put("projectName", innerDetailsVos.get(0).getProjectName());
        if (array.size() != 0) {
            json.put("version", changes.getVersion());
            json.put("dataList", array);
            json.put("moldSelectionId", moldSelectionId);
        }
        return JSON.toJSONString(R.data(json), SerializerFeature.WriteNullNumberAsZero, SerializerFeature.WriteNullListAsEmpty, SerializerFeature.WriteNullStringAsEmpty, SerializerFeature.WriteNullBooleanAsFalse);
    }

    /**
     * 封装详情表的数据
     *
     * @param details
     * @return
     */
    private List<InnerDetailsVo> setDetailsValues(List<InnerDesignChangesDetail> details) {
        List<InnerDetailsVo> values = new ArrayList<>();
        //将数据封装到Vo中
        for (InnerDesignChangesDetail detail : details
        ) {
            //详情Vo
            InnerDetailsVo innerDetailsVo = new InnerDetailsVo();
            BeanUtils.copyProperties(detail, innerDetailsVo);
            innerDetailsVo.setDesignFee(MyUtils.formatDouble(detail.getDesignFee()));
            innerDetailsVo.setProgramFee(MyUtils.formatDouble(detail.getProgramFee()));
            innerDetailsVo.setPackageFee(MyUtils.formatDouble(detail.getPackageFee()));
            innerDetailsVo.setTryoutFee(MyUtils.formatDouble(detail.getTryoutFee()));
            innerDetailsVo.setTransportFee(MyUtils.formatDouble(detail.getTransportFee()));
            innerDetailsVo.setManufacturingFee(MyUtils.formatDouble(detail.getManufacturingFee()));
            innerDetailsVo.setPeriodFee(MyUtils.formatDouble(detail.getPeriodFee()));
            innerDetailsVo.setPriceWithoutTax(MyUtils.formatDouble(detail.getPriceWithoutTax()));
            innerDetailsVo.setGrossProfit(MyUtils.formatDouble(detail.getGrossProfit()));
            innerDetailsVo.setTotalFee(MyUtils.formatDouble(detail.getTotalFee()));
            innerDetailsVo.setTotalFeeCheck(MyUtils.formatDouble(detail.getTotalFeeCheck()));
            //需要单独设置对象的值
            OuterMaterialFeeVo outerMaterialFeeVo = setOuterMaterialFeeVo(detail.getElectrodeFee(), detail.getKeyComponentFee(), detail.getStandardComponentFee());
            innerDetailsVo.setMaterialFee(outerMaterialFeeVo);

            innerDetailsVo.setManufacturingAndProcessingTargetFee(MyUtils.formatDouble(detail.getManufactureFee()));

            innerDetailsVo.setDetail(setDetail(detail));

            values.add(innerDetailsVo);
        }
        return values;
    }

    /**
     * 封装材料费用到OuterMaterialFeeVo
     *
     * @param electrodeFee
     * @param keyPartsFee
     * @param normalPartsFee
     * @return
     */
    private OuterMaterialFeeVo setOuterMaterialFeeVo(String electrodeFee, String keyPartsFee, String normalPartsFee) {
        OuterMaterialFeeVo fee = new OuterMaterialFeeVo();
        fee.setElectrodeFee(MyUtils.formatDouble(electrodeFee));
        fee.setStandardComponentFee(MyUtils.formatDouble(normalPartsFee));
        fee.setKeyComponentFee(MyUtils.formatDouble(keyPartsFee));
        return fee;
    }

    /**
     * 封装制造加工成本目标价到ManufacturingAndProcessingTargetFeeVo
     *
     * @param outsourceFee
     * @param selfManufactureFee
     * @return
     */
    private ManufacturingAndProcessingTargetFeeVo setManufacturing(String outsourceFee, String selfManufactureFee) {
        ManufacturingAndProcessingTargetFeeVo vo = new ManufacturingAndProcessingTargetFeeVo();
        vo.setOutsourceFee(MyUtils.formatDouble(outsourceFee));
        vo.setSelfManufactureFee(MyUtils.formatDouble(selfManufactureFee));
        return vo;
    }

    /**
     * 封装price表的数据到DetailVo
     *
     * @param detail
     * @return
     */
    private DetailVo setDetail(InnerDesignChangesDetail detail) {
        DetailVo detailVo = new DetailVo();
        List<InnerDesignChangePrice> feeObjectList = priceService.list(
                new LambdaQueryWrapper<InnerDesignChangePrice>()
                        .eq(InnerDesignChangePrice::getDesignChangeId, detail.getId()));
        BeanUtils.copyProperties(detail, detailVo);
        detailVo.setMoldHeight(MyUtils.formatDouble(detail.getMoldHeight()));
        detailVo.setMoldLength(MyUtils.formatDouble(detail.getMoldLength()));
        detailVo.setMoldWidth(MyUtils.formatDouble(detail.getMoldWidth()));
        detailVo.setMainFeeCheck(MyUtils.formatDouble(detail.getMainFeeCheck()));
        detailVo.setMaterialFeeCheck(MyUtils.formatDouble(detail.getMaterialFeeCheck()));
        detailVo.setTotalFeeCheck(MyUtils.formatDouble(detail.getTotalFeeCheck()));

        //需要单独设置的对象
        detailVo.setDesignFeeObject(setFeeDetail(feeObjectList, "设计费用"));
        detailVo.setProcessFeeObject(setFeeDetail(feeObjectList, "加工费用"));
        detailVo.setMeasureFeeObject(setFeeDetail(feeObjectList, "检测费用"));
        detailVo.setTryoutFeeObject(setFeeDetail(feeObjectList, "试模费用"));
        detailVo.setTransportFeeObject(setFeeDetail(feeObjectList, "运输费用"));
        detailVo.setMaterialFeeObject(setFeeDetail(feeObjectList, "材料费用"));
        detailVo.setOtherFeeObject(setFeeDetail(feeObjectList, "其它费用"));

        return detailVo;
    }

    /**
     * 封装price表的详情到FeeDetailVo
     *
     * @param feeObjectList
     * @param type
     * @return
     */
    private FeeDetailVo setFeeDetail(List<InnerDesignChangePrice> feeObjectList, String type) {
        List<InnerDesignChangePriceVo> list = new ArrayList<>();
        BigDecimal subTotal = new BigDecimal("0");
        for (InnerDesignChangePrice res : feeObjectList
        ) {
            //复制属性到vo
            InnerDesignChangePriceVo priceVo = new InnerDesignChangePriceVo();
            BeanUtils.copyProperties(res, priceVo);
            //需要单独赋值的属性
            if (res.getType().equals(type)) {
                priceVo.setSpecification(res.getSpecification());
                if (res.getNum() != null) {
                    if (res.getType().equals("材料费用")) priceVo.setWeight(Double.parseDouble(res.getNum()));
                    else if (res.getType().equals("其它费用")) priceVo.setRatio(res.getNum());
                    else {
                        priceVo.setHour(Double.parseDouble(res.getNum()));
                    }
                }

                priceVo.setPrice(MyUtils.formatDouble(res.getPrice()));
                //计算小计
                BigDecimal partTotal = BigdecimalUtil.stringToBigDecimal(res.getTotalPrice());
                subTotal = subTotal.add(partTotal);
                priceVo.setTotalPrice(partTotal.doubleValue());
                priceVo.setCheckPrice(MyUtils.formatDouble(res.getCheckPrice()));
                list.add(priceVo);
            }
        }

        FeeDetailVo feeDetailVo = new FeeDetailVo();
        feeDetailVo.setSubTotal(subTotal.doubleValue());
        feeDetailVo.setDataList(list);
        return feeDetailVo;
    }

    @Override
    public String deleteInnerDesignChangeSubTableById(JSONObject jsonObject, HttpServletRequest request) {
        //解析获取选模表Id
        String moldSelectionId = jsonObject.getString("moldSelectionId");
        //解析获取分表Id,即是详情表的id
        String subTableId = jsonObject.getString("subTableId");
        //删除的事务
        TransactionStatus status = transactionManager.getTransaction(new DefaultTransactionDefinition());

        try {
            //根据详情表的id删除详情表的数据
            InnerDesignChangesDetail innerDesignChangesDetail = detailService.getOne(new LambdaQueryWrapper<InnerDesignChangesDetail>().eq(InnerDesignChangesDetail::getId, subTableId));
            detailService.remove(new LambdaQueryWrapper<InnerDesignChangesDetail>().eq(InnerDesignChangesDetail::getId, subTableId));
            //根据详情表的id删除价格表的价格数据
            priceService.remove(new LambdaQueryWrapper<InnerDesignChangePrice>().eq(InnerDesignChangePrice::getDesignChangeId, subTableId));
            //查询到设变表的数据
            InnerDesignChanges innerDesignChanges = changesService.getOne(new LambdaQueryWrapper<InnerDesignChanges>().eq(InnerDesignChanges::getMoldSelectionId, moldSelectionId));

            //计算删除详情表后的总金额
            if (innerDesignChanges != null) {
                BigDecimal totalPrice = BigdecimalUtil.stringToBigDecimal(innerDesignChanges.getTotalPrice()).subtract(BigdecimalUtil.stringToBigDecimal(innerDesignChangesDetail.getPriceWithoutTax()));
                if (totalPrice.doubleValue() < 0) return JSON.toJSONString(R.fail("数据库数据异常"));
                innerDesignChanges.setTotalPrice(BigdecimalUtil.bigDecimalTo2DecimalString(totalPrice));
                int version = innerDesignChanges.getVersion() + 1;
                innerDesignChanges.setVersion(version);
                //将修改后的金额写回到数据库中
                final boolean update = changesService.update(innerDesignChanges, new LambdaQueryWrapper<InnerDesignChanges>().eq(InnerDesignChanges::getMoldSelectionId, moldSelectionId));
                if (update) {
                    //保存修改记录
                    String id = MyUtils.getHeader(request).getId();
                    String name = MyUtils.getName(id);
                    InnerDesignChangesChange innerDesignChangesChange = new InnerDesignChangesChange();
                    innerDesignChangesChange.setTime(LocalDateTime.now());
                    innerDesignChangesChange.setVersion(version);
                    innerDesignChangesChange.setUpdateById(id);
                    innerDesignChangesChange.setUpdateByName(name);
                    innerDesignChangesChange.setMoldSelectionId(moldSelectionId);
                    innerDesignChangesChangeMapper.insert(innerDesignChangesChange);
                }
            }
            transactionManager.commit(status);
        } catch (RuntimeException e) {
            transactionManager.rollback(status);
            return JSON.toJSONString(R.fail("删除失败"));
        }
        return JSON.toJSONString(R.success("删除成功"));
    }

    @Override
    public String saveInnerDesignChangeDetail(JSONObject jsonObject, HttpServletRequest request) {
        //jsonobject解析获取备用参数6
//        String param6 = jsonObject.getString("param6");
//        //jsonobject解析获取备用参数7
//        String param7 = jsonObject.getString("param7");
//        //jsonobject解析获取备用参数8
//        String param8 = jsonObject.getString("param8");
//        //jsonobject解析获取备用参数9
//        String param9 = jsonObject.getString("param9");
//        //jsonobject解析获取备用参数5
//        String param5 = jsonObject.getString("param5");
//        //jsonobject解析获取备用参数4
//        String param4 = jsonObject.getString("param4");
//        //jsonobject解析获取备用参数2
//        String param2 = jsonObject.getString("param2");
//        //jsonobject解析获取备用参数3
//        String param3 = jsonObject.getString("param3");
//        //jsonobject解析获取备用参数1
//        String param1 = jsonObject.getString("param1");
        //jsonobject解析获取项目名称
        String projectName = jsonObject.getString("projectName");
        //jsonobject解析获取总价
        String totalFee = jsonObject.getString("totalFee");
        BigDecimal totalFeeDouble = new BigDecimal("0");
        //jsonobject解析获取选模表id
        String moldSelectionId = jsonObject.getString("moldSelectionId");
        //jsonobject解析获取列表数据
        JSONArray dataList = jsonObject.getJSONArray("dataList");
        //开启事务
        TransactionStatus status = transactionManager.getTransaction(new DefaultTransactionDefinition());
        //将每一条的详情表数据插入到数据库
        try {
            for (int i = 0; i < dataList.size(); i++) {
                InnerDesignChangesDetail details = new InnerDesignChangesDetail();
                //获取dataList的对象
                JSONObject targetObject = dataList.getJSONObject(i);
                //获取dataList中的detail对象
                InnerDetailsVo innerDetailsVo = JSON.parseObject(targetObject.toJSONString(), InnerDetailsVo.class);
                OuterMaterialFeeVo materialVo = innerDetailsVo.getMaterialFee();
                JSONObject detail = targetObject.getJSONObject("detail");
                // 主页内容复制到表对象中
                BeanUtils.copyProperties(innerDetailsVo, details);
                details.setDesignFee(BigdecimalUtil.doubleTo2DecimalString(innerDetailsVo.getDesignFee()));
                details.setProgramFee(BigdecimalUtil.doubleTo2DecimalString(innerDetailsVo.getProgramFee()));
                details.setPackageFee(BigdecimalUtil.doubleTo2DecimalString(innerDetailsVo.getPackageFee()));
                details.setTryoutFee(BigdecimalUtil.doubleTo2DecimalString(innerDetailsVo.getTryoutFee()));
                details.setTransportFee(BigdecimalUtil.doubleTo2DecimalString(innerDetailsVo.getTransportFee()));
                details.setManufacturingFee(BigdecimalUtil.doubleTo2DecimalString(innerDetailsVo.getManufacturingFee()));
                details.setPeriodFee(BigdecimalUtil.doubleTo2DecimalString(innerDetailsVo.getPeriodFee()));
                details.setPriceWithoutTax(BigdecimalUtil.doubleTo2DecimalString(innerDetailsVo.getPriceWithoutTax()));
                details.setGrossProfit(BigdecimalUtil.doubleTo2DecimalString(innerDetailsVo.getGrossProfit()));
                details.setTotalFee(BigdecimalUtil.doubleTo2DecimalString(innerDetailsVo.getTotalFee()));
                details.setManufactureFee(BigdecimalUtil.doubleTo2DecimalString(innerDetailsVo.getManufacturingAndProcessingTargetFee()));
                // 详情页内容复制到表对象中
                DetailVo detailVo = innerDetailsVo.getDetail();
                BeanUtils.copyProperties(detailVo, details);
                details.setMoldHeight(BigdecimalUtil.double2IntegerString(detailVo.getMoldHeight()));
                details.setMoldLength(BigdecimalUtil.double2IntegerString(detailVo.getMoldLength()));
                details.setMoldWidth(BigdecimalUtil.double2IntegerString(detailVo.getMoldWidth()));
                details.setMainFeeCheck(BigdecimalUtil.doubleTo2DecimalString(detailVo.getMainFeeCheck()));
                details.setMaterialFeeCheck(BigdecimalUtil.doubleTo2DecimalString(detailVo.getMaterialFeeCheck()));
                details.setTotalFeeCheck(BigdecimalUtil.doubleTo2DecimalString(detailVo.getTotalFeeCheck()));
                if (materialVo != null) {
                    details.setElectrodeFee(BigdecimalUtil.doubleTo2DecimalString(materialVo.getElectrodeFee()));
                    details.setKeyComponentFee(BigdecimalUtil.doubleTo2DecimalString(materialVo.getKeyComponentFee()));
                    details.setStandardComponentFee(BigdecimalUtil.doubleTo2DecimalString(materialVo.getStandardComponentFee()));
                } else {
                    details.setElectrodeFee("0.00");
                    details.setKeyComponentFee("0.00");
                    details.setStandardComponentFee("0.00");
                }
                //判断核价目标毛利润和目标毛利润是否相等
                JSONObject materialFeeJSONObject = targetObject.getJSONObject("materialFee");
                double electrodeFee = 0;
                double keyComponentFee = 0;
                double standardComponentFee = 0;

                if (materialFeeJSONObject != null) {
                    electrodeFee = materialFeeJSONObject.getDoubleValue("electrodeFee");
                    keyComponentFee = materialFeeJSONObject.getDoubleValue("keyPartsFee");
                    standardComponentFee = materialFeeJSONObject.getDoubleValue("normalPartsFee");
                }
                BigDecimal electrodeFeeBig = BigdecimalUtil.double2BigDecimal2Decimal(electrodeFee);
                BigDecimal keyComponentFeeBig = BigdecimalUtil.double2BigDecimal2Decimal(keyComponentFee);
                BigDecimal standardComponentFeeBig = BigdecimalUtil.double2BigDecimal2Decimal(standardComponentFee);

                double manufacturingAndProcessingTargetFee = targetObject.getDoubleValue("manufacturingAndProcessingTargetFee");
                BigDecimal manufactureFeeBig = BigdecimalUtil.double2BigDecimal2Decimal(manufacturingAndProcessingTargetFee);
                double designFee = targetObject.getDoubleValue("designFee");
                BigDecimal designFeeBig = BigdecimalUtil.double2BigDecimal2Decimal(designFee);
                double priceWithoutTax = targetObject.getDoubleValue("finalTaxNotIncluded");
                BigDecimal priceWithoutTaxBig = BigdecimalUtil.double2BigDecimal2Decimal(priceWithoutTax);
                totalFeeDouble = totalFeeDouble.add(priceWithoutTaxBig);
                double transportFee = targetObject.getDoubleValue("transportFee");
                BigDecimal transportFeeBig = BigdecimalUtil.double2BigDecimal2Decimal(transportFee);
                double manufacturingFee = targetObject.getDoubleValue("manufacturingFee");
                BigDecimal manufacturingFeeBig = BigdecimalUtil.double2BigDecimal2Decimal(manufacturingFee);
                double periodFee = targetObject.getDoubleValue("periodFee");
                BigDecimal periodFeeBig = BigdecimalUtil.double2BigDecimal2Decimal(periodFee);
                double grossProfit = targetObject.getDoubleValue("targetGrossProfit");
                BigDecimal grossProfitBig = BigdecimalUtil.double2BigDecimal2Decimal(grossProfit);
                double programmingFee = targetObject.getDoubleValue("programmingFee");
                BigDecimal programmingFeeBig = BigdecimalUtil.double2BigDecimal2Decimal(programmingFee);
                double tryOutFee = targetObject.getDoubleValue("tryoutFee");
                BigDecimal tryOutFeeBig = BigdecimalUtil.double2BigDecimal2Decimal(tryOutFee);
                double packingMaterialFee = targetObject.getDoubleValue("packingMaterialFee");
                BigDecimal packingMaterialFeeBig = BigdecimalUtil.double2BigDecimal2Decimal(packingMaterialFee);
                BigDecimal count1 = manufacturingFeeBig.add(transportFeeBig);
                BigDecimal count2 = count1.add(tryOutFeeBig);
                BigDecimal count3 = count2.add(programmingFeeBig);
                BigDecimal count4 = count3.add(packingMaterialFeeBig);
                BigDecimal count5 = count4.add(designFeeBig);
                BigDecimal count6 = count5.add(manufactureFeeBig);
                BigDecimal count8 = count6.add(electrodeFeeBig);
                BigDecimal count9 = count8.add(keyComponentFeeBig);
                BigDecimal count10 = count9.add(standardComponentFeeBig);
                BigDecimal count11 = count10.add(periodFeeBig);
                BigDecimal checkGrossProfit = priceWithoutTaxBig.subtract(count11).setScale(2, RoundingMode.HALF_UP);
                //计算核价目标毛利润
                String grossProfitRatioString = targetObject.getString("percentageOfFinalProcessTargetGrossProfit");

                double grossProfitRatio = 0;
                if (ObjectUtil.isNotNull(grossProfitRatioString) && grossProfitRatioString.contains("%")) {
                    grossProfitRatio = MyUtils.formatDouble(grossProfitRatioString.replaceAll("%", ""));
                }
                BigDecimal grossProfitRatioBig = BigdecimalUtil.double2BigDecimal2Decimal(grossProfitRatio);
                //校验运输费
                if (priceWithoutTaxBig.multiply(new BigDecimal("0.035")).setScale(2, RoundingMode.HALF_UP).compareTo(transportFeeBig.setScale(2, RoundingMode.HALF_UP)) != 0)
                    throw new RuntimeException("保存失败，运输费有问题");
                //校验制造费
                if (priceWithoutTaxBig.multiply(new BigDecimal("0.05")).setScale(2, RoundingMode.HALF_UP).compareTo(manufacturingFeeBig.setScale(2, RoundingMode.HALF_UP)) != 0)
                    throw new RuntimeException("保存失败，制造费有问题");
                //校验期间费
                if (priceWithoutTaxBig.multiply(new BigDecimal("0.155")).setScale(2, RoundingMode.HALF_UP).compareTo(periodFeeBig.setScale(2, RoundingMode.HALF_UP)) != 0)
                    throw new RuntimeException("保存失败，期间费有问题");
                //校验目标毛利润
                if (grossProfitBig.setScale(2, RoundingMode.HALF_UP).compareTo(checkGrossProfit) != 0)
                    throw new RuntimeException("保存失败，目标毛利润有问题");
                //校验最终工序目标毛利润占比
                if (priceWithoutTax == 0) throw new RuntimeException("保存失败，最终未含税不能为0");
                if (grossProfitBig.divide(priceWithoutTaxBig, 5, RoundingMode.HALF_UP).multiply(new BigDecimal("100")).setScale(2, RoundingMode.HALF_UP).compareTo(grossProfitRatioBig.setScale(2, RoundingMode.HALF_UP)) != 0)
                    throw new RuntimeException("保存失败，最终工序目标毛利润占比有问题");
                //计算模具尺寸
                String moldLength = BigdecimalUtil.double2IntegerString(detail.getDoubleValue("lengthOfMold"));
                String moldWidth = BigdecimalUtil.double2IntegerString(detail.getDoubleValue("widthOfMold"));
                String moldHeight = BigdecimalUtil.double2IntegerString(detail.getDoubleValue("heightOfMold"));
                String moldSize = moldLength + "*" + moldWidth + "*" + moldHeight;
                //保存费用，并返回每条费用的核价明细
                JSONObject designFeeObject = detail.getJSONObject("designFeeObject");
                String designFeeTotal = BigdecimalUtil.stringTo2DecimalString(designFeeObject.getString("subTotal"));
                JSONObject processFeeObject = detail.getJSONObject("processFeeObject");
                String machiningFeeTotal = BigdecimalUtil.stringTo2DecimalString(processFeeObject.getString("subTotal"));
                JSONObject measureFeeObject = detail.getJSONObject("measureFeeObject");
                String testFeeTotal = BigdecimalUtil.stringTo2DecimalString(measureFeeObject.getString("subTotal"));
                JSONObject tryoutFeeObject = detail.getJSONObject("tryoutFeeObject");
                String tryoutFeeTotal = BigdecimalUtil.stringTo2DecimalString(tryoutFeeObject.getString("subTotal"));
                JSONObject transportFeeObject = detail.getJSONObject("transportFeeObject");
                String transportFeeTotal = BigdecimalUtil.stringTo2DecimalString(transportFeeObject.getString("subTotal"));
                JSONObject materialFeeObject = detail.getJSONObject("materialFeeObject");
                String materialFeeTotal = BigdecimalUtil.stringTo2DecimalString(materialFeeObject.getString("subTotal"));
                JSONObject otherFeeObject = detail.getJSONObject("otherFeeObject");
                String otherFeeTotal = BigdecimalUtil.stringTo2DecimalString(otherFeeObject.getString("subTotal"));
                //某些单独处理或赋值的数据手动保存
                details.setMoldSelectionId(moldSelectionId);
                details.setProjectName(projectName);
                details.setMoldSize(moldSize);
                details.setDesignFeeTotal(designFeeTotal);
                details.setMachiningFeeTotal(machiningFeeTotal);
                details.setTestFeeTotal(testFeeTotal);
                details.setTryoutFeeTotal(tryoutFeeTotal);
                details.setTransportFeeTotal(transportFeeTotal);
                details.setMaterialFeeTotal(materialFeeTotal);
                details.setOtherFeeTotal(otherFeeTotal);
                details.setMainFeeCheck(BigdecimalUtil.doubleTo2DecimalString(detail.getDoubleValue("mainFeeCheck")));
                details.setMaterialFeeCheck(BigdecimalUtil.doubleTo2DecimalString(detail.getDoubleValue("materialFeeCheck")));
                details.setTotalFeeCheck(BigdecimalUtil.doubleTo2DecimalString(detail.getDoubleValue("totalFeeCheck")));
                String maker = detail.getString("projectManager");
                details.setMaker((StringUtils.isEmpty(maker) ? "" : maker));
                String auditor = detail.getString("checkoutName");
                details.setAuditor((StringUtils.isEmpty(auditor) ? "" : auditor));
                String approver = detail.getString("approver");
                details.setApprover((StringUtils.isEmpty(approver) ? "" : approver));
                detailService.saveOrUpdate(details);
                //保存到Price表
                String id = details.getId();
                BigDecimal designFeeCheck = saveInnerPrice(id, moldSelectionId, designFeeObject, "设计费用", designFeeTotal);
                BigDecimal processFeeCheck = saveInnerPrice(id, moldSelectionId, processFeeObject, "加工费用", machiningFeeTotal);
                BigDecimal measureFeeCheck = saveInnerPrice(id, moldSelectionId, measureFeeObject, "检测费用", testFeeTotal);
                BigDecimal tryOutFeeCheck = saveInnerPrice(id, moldSelectionId, tryoutFeeObject, "试模费用", tryoutFeeTotal);
                BigDecimal transportFeeCheck = saveInnerPrice(id, moldSelectionId, transportFeeObject, "运输费用", transportFeeTotal);
                BigDecimal materialFeeCheck = saveInnerPrice(id, moldSelectionId, materialFeeObject, "材料费用", materialFeeTotal);
                BigDecimal otherFeeCheck = saveInnerPrice(id, moldSelectionId, otherFeeObject, "其它费用", otherFeeTotal);

//                double mainFeeCheck = designFeeCheck + processFeeCheck + measureFeeCheck + tryOutFeeCheck + transportFeeCheck;
//                //主要费用核价
//                if (detail.getDoubleValue("mainFeeCheck")==null || mainFeeCheck != detail.getDoubleValue("mainFeeCheck")) {
//                    throw new RuntimeException("保存失败，主要费用与核价费用不一致");
//                }
//                //材料费用核价
//                if (detail.getDoubleValue("materialFeeCheck")==null || materialFeeCheck != detail.getDoubleValue("materialFeeCheck"))
//                    throw new RuntimeException("保存失败，材料费用与核价费用不一致");
//                //总费用核价
//                if (detail.getDoubleValue("totalFeeCheck")==null || (otherFeeCheck + materialFeeCheck + mainFeeCheck) != detail.getDoubleValue("totalFeeCheck"))
//                    throw new RuntimeException("保存失败，总费用与核价费用不一致");
            }
            if (totalFeeDouble.compareTo(BigdecimalUtil.stringToBigDecimal(totalFee)) != 0) {
                throw new RuntimeException("总费用核价不一致");
            }
            //保存change表
            boolean b = saveChanges(totalFeeDouble, moldSelectionId, request);
            //设变目标审批表-编辑-明细表的初始数据由相应设变目标价格表继承数据
            if (b) {
                List<InnerDesignChangesDetail> innerDesignChangesDetails = detailService.list(
                        new LambdaQueryWrapper<InnerDesignChangesDetail>()
                                .eq(InnerDesignChangesDetail::getMoldSelectionId, moldSelectionId));
                BigDecimal supplierFeeTotal = new BigDecimal(0);
                for (InnerDesignChangesDetail innerDesignChangesDetail : innerDesignChangesDetails) {
                    OuterDesignChangesDetail outerDesignChangesDetail = innerDesignChangesDetail2OuterDesignChangesDetail(innerDesignChangesDetail);
                    supplierFeeTotal = BigdecimalUtil.stringToBigDecimal(outerDesignChangesDetail.getSupplierFee()).add(supplierFeeTotal);
                    //继承Detail表数据
                    boolean boolOuterDesignChangesDetail = iOuterDesignChangesDetailService
                            .save(outerDesignChangesDetail);
                    if (boolOuterDesignChangesDetail) {
                        String outerDesignChangesDetailId = outerDesignChangesDetail.getId();
                        List<InnerDesignChangePrice> innerDesignChangePriceList = priceService.list(
                                new LambdaQueryWrapper<InnerDesignChangePrice>()
                                        .eq(InnerDesignChangePrice::getDesignChangeId, innerDesignChangesDetail.getId()));
                        for (InnerDesignChangePrice innerDesignChangePrice : innerDesignChangePriceList) {
                            OuterDesignChangePrice outerDesignChangePrice = new OuterDesignChangePrice();
                            BeanUtils.copyProperties(innerDesignChangePrice, outerDesignChangePrice);
                            outerDesignChangePrice.setId(null);
                            outerDesignChangePrice.setDesignChangeId(outerDesignChangesDetailId);
                            //继承Price表数据
                            boolean bOuterDesignChangePrice = iOuterDesignChangePriceService
                                    .save(outerDesignChangePrice);
                            if (!bOuterDesignChangePrice) {
                                throw new RuntimeException("设变目标审批表继承数据失败");
                            }
                        }
                    } else {
                        throw new RuntimeException("设变目标审批表继承数据失败");
                    }
                }

                //继承主表数据
                int version = 1;
                OuterDesignChanges outerDesignChanges = new OuterDesignChanges();
                outerDesignChanges.setMoldSelectionId(moldSelectionId);
                outerDesignChanges.setSupplierFeeTotal(BigdecimalUtil.bigDecimalTo2DecimalString(supplierFeeTotal));
                outerDesignChanges.setVersion(version);
                boolean boolOuterDesignChanges = iOuterDesignChangesService.save(outerDesignChanges);
                if (!boolOuterDesignChanges) {
                    throw new RuntimeException("设变目标审批表继承数据失败");
                }
                //保存修改记录
                String id = MyUtils.getHeader(request).getId();
                String name = MyUtils.getName(id);
                OuterDesignChangesChange outerDesignChangesChange = new OuterDesignChangesChange();
                outerDesignChangesChange.setTime(LocalDateTime.now());
                outerDesignChangesChange.setVersion(version);
                outerDesignChangesChange.setUpdateById(id);
                outerDesignChangesChange.setUpdateByName(name);
                outerDesignChangesChange.setMoldSelectionId(moldSelectionId);
                outerDesignChangesChangeMapper.insert(outerDesignChangesChange);
            }
            //提交事务
            transactionManager.commit(status);
        } catch (RuntimeException e) {
            //回滚事务
            transactionManager.rollback(status);
            return JSON.toJSONString(R.fail(e.getMessage()));
        }
        return JSON.toJSONString(R.success("保存成功"));
    }

    private OuterDesignChangePrice innerDesignChangePrice2OuterDesignChangePrice(InnerDesignChangePrice innerDesignChangePrice) {
        OuterDesignChangePrice outerDesignChangePrice = new OuterDesignChangePrice();
        return outerDesignChangePrice;
    }

    private OuterDesignChangesDetail innerDesignChangesDetail2OuterDesignChangesDetail(InnerDesignChangesDetail innerDesignChangesDetail) {
        OuterDesignChangesDetail outerDesignChangesDetail = new OuterDesignChangesDetail();
        outerDesignChangesDetail.setMoldSelectionId(innerDesignChangesDetail.getMoldSelectionId());
        outerDesignChangesDetail.setMoldName(innerDesignChangesDetail.getMoldName());
        outerDesignChangesDetail.setMoldId(innerDesignChangesDetail.getMoldId());
        outerDesignChangesDetail.setTechnicalNoticeNumber(innerDesignChangesDetail.getTechnicalNoticeNumber());
        outerDesignChangesDetail.setProductTechnicalNoticeNumber(innerDesignChangesDetail.getProductTechnicalNoticeNumber());
        outerDesignChangesDetail.setContent(innerDesignChangesDetail.getContent());
        outerDesignChangesDetail.setTime(innerDesignChangesDetail.getTime());
        outerDesignChangesDetail.setSource("1");
        outerDesignChangesDetail.setProjectName(innerDesignChangesDetail.getProjectName());
        outerDesignChangesDetail.setProductName(innerDesignChangesDetail.getProductName());
        outerDesignChangesDetail.setDesignChangesCode(innerDesignChangesDetail.getDesignChangesCode());
        outerDesignChangesDetail.setChangedPeriod(innerDesignChangesDetail.getChangedPeriod());
        outerDesignChangesDetail.setProductImage(innerDesignChangesDetail.getProductImage());
        outerDesignChangesDetail.setMoldLength(innerDesignChangesDetail.getMoldLength());
        outerDesignChangesDetail.setMoldWidth(innerDesignChangesDetail.getMoldWidth());
        outerDesignChangesDetail.setMoldHeight(innerDesignChangesDetail.getMoldHeight());
        outerDesignChangesDetail.setDeviceId(innerDesignChangesDetail.getDeviceId());
        outerDesignChangesDetail.setPress(innerDesignChangesDetail.getPress());
        outerDesignChangesDetail.setRectificationPlan(innerDesignChangesDetail.getRectificationPlan());
        outerDesignChangesDetail.setDesignFeeTotal(innerDesignChangesDetail.getDesignFeeTotal());
        outerDesignChangesDetail.setMachiningFeeTotal(innerDesignChangesDetail.getMachiningFeeTotal());
        outerDesignChangesDetail.setTestFeeTotal(innerDesignChangesDetail.getTestFeeTotal());
        outerDesignChangesDetail.setTryoutFeeTotal(innerDesignChangesDetail.getTryoutFeeTotal());
        outerDesignChangesDetail.setTransportFeeTotal(innerDesignChangesDetail.getTransportFeeTotal());
        outerDesignChangesDetail.setMainFeeCheck(innerDesignChangesDetail.getMainFeeCheck());
        outerDesignChangesDetail.setMaterialFeeTotal(innerDesignChangesDetail.getMaterialFeeTotal());
        outerDesignChangesDetail.setMaterialFeeCheck(innerDesignChangesDetail.getMaterialFeeCheck());
        outerDesignChangesDetail.setOtherFeeTotal(innerDesignChangesDetail.getOtherFeeTotal());
        outerDesignChangesDetail.setSupplier(innerDesignChangesDetail.getSupplier());
        outerDesignChangesDetail.setBidder(innerDesignChangesDetail.getBidder());
        outerDesignChangesDetail.setTotalFee(innerDesignChangesDetail.getTotalFee());
        outerDesignChangesDetail.setTotalFeeCheck(innerDesignChangesDetail.getTotalFeeCheck());
        outerDesignChangesDetail.setSupplierFee(innerDesignChangesDetail.getTotalFee());
        outerDesignChangesDetail.setMaker(innerDesignChangesDetail.getMaker());
        outerDesignChangesDetail.setAuditor(innerDesignChangesDetail.getAuditor());
        outerDesignChangesDetail.setApprover(innerDesignChangesDetail.getApprover());
        outerDesignChangesDetail.setIsApprove(innerDesignChangesDetail.getIsApprove());
        return outerDesignChangesDetail;
    }

    /**
     * 初始化方法，用于在保存数据之前的保存操作
     *
     * @param moldSelectionId
     * @param detailId
     */
    private void init(String moldSelectionId, String detailId) {
        List<InnerDesignChangePrice> list = Lists.newArrayList();
        for (InnerDesignChangePriceEnum enums : InnerDesignChangePriceEnum.values()) {
            InnerDesignChangePrice price = new InnerDesignChangePrice();
            price.setMoldSelectionId(moldSelectionId);
            price.setDesignChangeId(detailId);
            price.setType(enums.type);
            price.setName(enums.name);
            price.setNum(enums.num + "");
            if (ObjectUtil.isNotNull(enums.price)) {
                price.setPrice(enums.price + "");
            }
            price.setTotalPrice(enums.totalPrice + "");
            price.setCheckPrice(enums.checkPrice + "");
            if (ObjectUtil.isNotNull(enums.length)) {
                price.setLength(enums.length + "");
            }
            if (ObjectUtil.isNotNull(enums.width)) {
                price.setWidth(enums.width + "");
            }
            if (ObjectUtil.isNotNull(enums.height)) {
                price.setHeight(enums.height + "");
            }
            list.add(price);
        }
        priceService.saveBatch(list);
    }

    /**
     * 保存change表数据的方法
     *
     * @param totalFee
     * @param moldSelectionId
     */
    private boolean saveChanges(BigDecimal totalFee, String moldSelectionId, HttpServletRequest request) {
        //是否为新增
        boolean isNew = false;
        InnerDesignChanges change = changesService.getOne(new LambdaQueryWrapper<InnerDesignChanges>().eq(InnerDesignChanges::getMoldSelectionId, moldSelectionId));
        Integer version;
        if (ObjectUtil.isEmpty(change)) {
            change = new InnerDesignChanges();
            version = 1;
            isNew = true;
        } else {
            version = change.getVersion() + 1;
        }
        change.setVersion(version);
        change.setMoldSelectionId(moldSelectionId);

        //如果不存在某个选模表的数据，则保存为一条新的change表数据，否则更新总价
        change.setTotalPrice(BigdecimalUtil.bigDecimalTo2DecimalString(totalFee));
        boolean b = changesService.saveOrUpdate(change);
        if (b) {
            //保存修改记录
            String id = MyUtils.getHeader(request).getId();
            String name = MyUtils.getName(id);
            InnerDesignChangesChange innerDesignChangesChange = new InnerDesignChangesChange();
            innerDesignChangesChange.setTime(LocalDateTime.now());
            innerDesignChangesChange.setVersion(version);
            innerDesignChangesChange.setUpdateById(id);
            innerDesignChangesChange.setUpdateByName(name);
            innerDesignChangesChange.setMoldSelectionId(moldSelectionId);
            innerDesignChangesChangeMapper.insert(innerDesignChangesChange);
        }
        if (isNew) {
            return b;
        }
        return false;
    }

    /**
     * 保存price表数据的方法
     *
     * @param subTableId
     * @param moldSelectionId
     * @param target
     * @param type
     * @return
     */
    private BigDecimal saveInnerPrice(String subTableId, String moldSelectionId, JSONObject target, String type, String subTotal) {
        JSONArray dataList = target.getJSONArray("dataList");
        BigDecimal subTotalSum = new BigDecimal("0");
        BigDecimal check = new BigDecimal("0");

        //保存所有科目的数据
        for (int i = 0; i < dataList.size(); i++) {
            InnerDesignChangePrice price = new InnerDesignChangePrice();
            JSONObject result = dataList.getJSONObject(i);
            String itemName = result.getString("itemName");
            InnerDesignChangePriceVo vo = JSON.toJavaObject(result, InnerDesignChangePriceVo.class);
            //赋值大部分属性到price对象
            BeanUtils.copyProperties(vo, price);

            //需要手动赋值的某些属性
            price.setMoldSelectionId(moldSelectionId);
            price.setDesignChangeId(subTableId);
            price.setType(type);
            //根据科目的不同设置num的值
            double num;
            if (price.getType().equals("材料费用")) {
                num = result.getDoubleValue("weight");
                price.setNum(BigdecimalUtil.doubleTo3DecimalString(num));

                BigDecimal length = BigdecimalUtil.double2BigDecimal2Decimal(result.getDoubleValue("lengthOfspecification"));
                BigDecimal width = BigdecimalUtil.double2BigDecimal2Decimal(result.getDoubleValue("widthOfspecification"));
                BigDecimal height = BigdecimalUtil.double2BigDecimal2Decimal(result.getDoubleValue("heightOfspecification"));
                double weightResult = length.multiply(width).multiply(height).multiply(new BigDecimal("0.00000785")).setScale(3, RoundingMode.HALF_UP).doubleValue();

                if (weightResult != num) {
                    throw new RuntimeException(type + "-" + itemName + "重量计算结果不一致。结果为" + weightResult);
                }
            } else if (price.getType().equals("其它费用")) {
                num = result.getDoubleValue("ratio");
                price.setNum(BigdecimalUtil.doubleTo2DecimalString(num));
            } else {
                num = result.getDoubleValue("hour");
                price.setNum(BigdecimalUtil.doubleTo2DecimalString(num));
            }
            BigDecimal numBigDecimal = BigdecimalUtil.double2BigDecimal3Decimal(num);
            BigDecimal totalPrice = BigdecimalUtil.double2BigDecimal2Decimal(result.getDoubleValue("totalPrice"));
            subTotalSum = subTotalSum.add(totalPrice);
            price.setTotalPrice(BigdecimalUtil.doubleTo2DecimalString(result.getDoubleValue("totalPrice")));
            if (!type.equals("其它费用")) {
                price.setPrice(BigdecimalUtil.doubleTo2DecimalString(result.getDoubleValue("price")));
                BigDecimal priceBigDecimal = BigdecimalUtil.double2BigDecimal2Decimal(result.getDoubleValue("price"));
                BigDecimal totalPriceBigDecimal = priceBigDecimal.multiply(numBigDecimal).setScale(2, RoundingMode.HALF_UP);
                if (totalPriceBigDecimal.compareTo(totalPrice) != 0) {
                    throw new RuntimeException(type + "-" + itemName + "金额计算结果不一致。结果为" + totalPriceBigDecimal.doubleValue());
                }
            }

            //根据是否存在checkPrice，设置checkPrice
            String checkPrice = result.getString("checkPrice");
            price.setCheckPrice(BigdecimalUtil.stringTo2DecimalString(checkPrice));
            check = check.add(BigdecimalUtil.stringToBigDecimal(checkPrice));
            priceService.saveOrUpdate(price, new LambdaUpdateWrapper<InnerDesignChangePrice>().eq(InnerDesignChangePrice::getDesignChangeId, subTableId).eq(InnerDesignChangePrice::getType, type).eq(InnerDesignChangePrice::getName, result.getString("itemName")));
        }
        if (subTotalSum.compareTo(BigdecimalUtil.stringToBigDecimal(subTotal)) != 0) {
            throw new RuntimeException(type + "-小计计算结果不一致。结果为" + subTotalSum);
        }
        return check;
    }

    @Override
    public String exportInnerDesignChange(JSONObject jsonObject, HttpServletResponse response) {
        //jsonobject解析获取选模表Id
        String moldSelectionId = jsonObject.getString("moldSelectionId");
        //jsonobject解析获取是否审批
        String isApprove = jsonObject.getString("isApprove");

        try {
            String filePath = writeExcel(moldSelectionId, isApprove);
            return JSON.toJSONString(R.data("filePath: " + filePath));
        } catch (Exception e) {
            return JSON.toJSONString(R.fail("excel生成失败"));
        }
    }

    /**
     * 克隆表格
     *
     * @param size
     */
    private byte[] cloneExcel(int size) throws Exception {
        try (InputStream inputStream = getClass().getClassLoader().getResourceAsStream("templates/inner_design_changes_template.xlsx");
             XSSFWorkbook workbook = new XSSFWorkbook(inputStream);
             ByteArrayOutputStream ops = new ByteArrayOutputStream()) {

            //默认有主表和明细1
            if (size > 1) {
                //明细条数大于1，克隆表格
                for (int i = 1; i < size; i++) {
                    workbook.cloneSheet(1, "单项报价明细" + (i + 1));
                }
            } else if (size == 0) {
                //明细条数为0，删除明细1
                workbook.removeSheetAt(1);
            }

            workbook.write(ops);
            return ops.toByteArray();
        } catch (IOException e) {
            e.printStackTrace();
            throw e;
        }
    }

    private String writeExcel(String moldSelectionId, String isApprove) {
        String projectName = iMoldSelectionService.getProjectName(moldSelectionId);
        String resultPath = "file" + File.separator + projectName + "项目-内部设变表-" + DateUtils.dateTimeNow("yyyyMMdd-SSS") + ".xlsx";
        String filePath = keyWord.getFileUrl() + File.separator + resultPath;
        InnerDesignChanges innerDesignChanges = changesService.getOne(new LambdaQueryWrapper<InnerDesignChanges>().eq(InnerDesignChanges::getMoldSelectionId, moldSelectionId));
        List<InnerDesignChangesDetail> details = detailService.list(
                new LambdaQueryWrapper<InnerDesignChangesDetail>()
                        .eq(InnerDesignChangesDetail::getMoldSelectionId, moldSelectionId)
                        .eq(StringUtils.isNotEmpty(isApprove), InnerDesignChangesDetail::getIsApprove, isApprove));
        int size = details.size();

        //创建一个工作簿
        XSSFWorkbook workbook = new XSSFWorkbook();
        //总表
        XSSFSheet sheet = workbook.createSheet("设变目标价格表");
        //列宽
        sheet.setColumnWidth(0, 6 * 256);
        sheet.setColumnWidth(1, 15 * 256);
        sheet.setColumnWidth(2, 15 * 256);
        sheet.setColumnWidth(3, 15 * 256);
        sheet.setColumnWidth(4, 15 * 256);
        sheet.setColumnWidth(5, 50 * 256);
        sheet.setColumnWidth(6, 20 * 256);
        sheet.setColumnWidth(7, 20 * 256);
        sheet.setColumnWidth(8, 20 * 256);
        sheet.setColumnWidth(9, 20 * 256);
        sheet.setColumnWidth(10, 20 * 256);
        sheet.setColumnWidth(11, 20 * 256);
        sheet.setColumnWidth(12, 15 * 256);
        sheet.setColumnWidth(13, 15 * 256);
        sheet.setColumnWidth(14, 15 * 256);
        sheet.setColumnWidth(15, 15 * 256);
        sheet.setColumnWidth(16, 15 * 256);
        sheet.setColumnWidth(17, 15 * 256);
        sheet.setColumnWidth(18, 15 * 256);
        sheet.setColumnWidth(19, 15 * 256);
        sheet.setColumnWidth(20, 15 * 256);
        sheet.setColumnWidth(21, 20 * 256);
        sheet.setColumnWidth(22, 20 * 256);

        //第一行
        CellRangeAddress cellRangeAddress1 = new CellRangeAddress(0, 0, 0, 22);
        ExcelUtil.setCellRangeBorderThin(sheet, cellRangeAddress1);
        sheet.addMergedRegion(cellRangeAddress1);
        //单元格格式
        XSSFCellStyle cellStyle1 = workbook.createCellStyle();
        cellStyle1.setAlignment(HorizontalAlignment.CENTER);
        cellStyle1.setVerticalAlignment(VerticalAlignment.CENTER);
        cellStyle1.setBorderBottom(BorderStyle.THIN); //下边框
        cellStyle1.setBorderLeft(BorderStyle.THIN);//左边框
        cellStyle1.setBorderTop(BorderStyle.THIN);//上边框
        cellStyle1.setBorderRight(BorderStyle.THIN);//右边框
        XSSFFont font1 = workbook.createFont();
        font1.setBold(true);
        font1.setFontName("宋体");
        font1.setFontHeightInPoints((short) 16);
        cellStyle1.setFont(font1);
        Row row1 = ExcelUtil.getRow(sheet, 0);
        row1.setHeightInPoints(36);
        Cell cell1 = ExcelUtil.getCell(row1, 0);
        cell1.setCellStyle(cellStyle1);
        cell1.setCellValue(projectName + "项目 设变目标价格表");

        //第二行
        CellRangeAddress cellRangeAddress2_0 = new CellRangeAddress(1, 2, 0, 0);
        ExcelUtil.setCellRangeBorderThin(sheet, cellRangeAddress2_0);
        sheet.addMergedRegion(cellRangeAddress2_0);
        CellRangeAddress cellRangeAddress2_1 = new CellRangeAddress(1, 2, 1, 1);
        ExcelUtil.setCellRangeBorderThin(sheet, cellRangeAddress2_1);
        sheet.addMergedRegion(cellRangeAddress2_1);
        CellRangeAddress cellRangeAddress2_2 = new CellRangeAddress(1, 2, 2, 2);
        ExcelUtil.setCellRangeBorderThin(sheet, cellRangeAddress2_2);
        sheet.addMergedRegion(cellRangeAddress2_2);
        CellRangeAddress cellRangeAddress2_3 = new CellRangeAddress(1, 2, 3, 3);
        ExcelUtil.setCellRangeBorderThin(sheet, cellRangeAddress2_3);
        sheet.addMergedRegion(cellRangeAddress2_3);
        CellRangeAddress cellRangeAddress2_4 = new CellRangeAddress(1, 2, 4, 4);
        ExcelUtil.setCellRangeBorderThin(sheet, cellRangeAddress2_4);
        sheet.addMergedRegion(cellRangeAddress2_4);
        CellRangeAddress cellRangeAddress2_5 = new CellRangeAddress(1, 2, 5, 5);
        ExcelUtil.setCellRangeBorderThin(sheet, cellRangeAddress2_5);
        sheet.addMergedRegion(cellRangeAddress2_5);
        CellRangeAddress cellRangeAddress2_6 = new CellRangeAddress(1, 2, 6, 6);
        ExcelUtil.setCellRangeBorderThin(sheet, cellRangeAddress2_6);
        sheet.addMergedRegion(cellRangeAddress2_6);
        CellRangeAddress cellRangeAddress2_7 = new CellRangeAddress(1, 1, 7, 9);
        ExcelUtil.setCellRangeBorderThin(sheet, cellRangeAddress2_7);
        sheet.addMergedRegion(cellRangeAddress2_7);
        CellRangeAddress cellRangeAddress2_10 = new CellRangeAddress(1, 1, 10, 11);
        ExcelUtil.setCellRangeBorderThin(sheet, cellRangeAddress2_10);
        sheet.addMergedRegion(cellRangeAddress2_10);
        CellRangeAddress cellRangeAddress2_12 = new CellRangeAddress(1, 2, 12, 12);
        ExcelUtil.setCellRangeBorderThin(sheet, cellRangeAddress2_12);
        sheet.addMergedRegion(cellRangeAddress2_12);
        CellRangeAddress cellRangeAddress2_13 = new CellRangeAddress(1, 2, 13, 13);
        ExcelUtil.setCellRangeBorderThin(sheet, cellRangeAddress2_13);
        sheet.addMergedRegion(cellRangeAddress2_13);
        CellRangeAddress cellRangeAddress2_14 = new CellRangeAddress(1, 2, 14, 14);
        ExcelUtil.setCellRangeBorderThin(sheet, cellRangeAddress2_14);
        sheet.addMergedRegion(cellRangeAddress2_14);
        CellRangeAddress cellRangeAddress2_15 = new CellRangeAddress(1, 2, 15, 15);
        ExcelUtil.setCellRangeBorderThin(sheet, cellRangeAddress2_15);
        sheet.addMergedRegion(cellRangeAddress2_15);
        CellRangeAddress cellRangeAddress2_16 = new CellRangeAddress(1, 2, 16, 16);
        ExcelUtil.setCellRangeBorderThin(sheet, cellRangeAddress2_16);
        sheet.addMergedRegion(cellRangeAddress2_16);
        CellRangeAddress cellRangeAddress2_17 = new CellRangeAddress(1, 2, 17, 17);
        ExcelUtil.setCellRangeBorderThin(sheet, cellRangeAddress2_17);
        sheet.addMergedRegion(cellRangeAddress2_17);
        CellRangeAddress cellRangeAddress2_18 = new CellRangeAddress(1, 2, 18, 18);
        ExcelUtil.setCellRangeBorderThin(sheet, cellRangeAddress2_18);
        sheet.addMergedRegion(cellRangeAddress2_18);
        CellRangeAddress cellRangeAddress2_19 = new CellRangeAddress(1, 2, 19, 19);
        ExcelUtil.setCellRangeBorderThin(sheet, cellRangeAddress2_19);
        sheet.addMergedRegion(cellRangeAddress2_19);
        CellRangeAddress cellRangeAddress2_20 = new CellRangeAddress(1, 2, 20, 20);
        ExcelUtil.setCellRangeBorderThin(sheet, cellRangeAddress2_20);
        sheet.addMergedRegion(cellRangeAddress2_20);
        CellRangeAddress cellRangeAddress2_21 = new CellRangeAddress(1, 2, 21, 21);
        ExcelUtil.setCellRangeBorderThin(sheet, cellRangeAddress2_21);
        sheet.addMergedRegion(cellRangeAddress2_21);
        CellRangeAddress cellRangeAddress2_22 = new CellRangeAddress(1, 2, 22, 22);
        ExcelUtil.setCellRangeBorderThin(sheet, cellRangeAddress2_22);
        sheet.addMergedRegion(cellRangeAddress2_22);
        XSSFCellStyle cellStyle2 = workbook.createCellStyle();
        cellStyle2.setAlignment(HorizontalAlignment.CENTER);
        cellStyle2.setVerticalAlignment(VerticalAlignment.CENTER);
        cellStyle2.setWrapText(true);
        cellStyle2.setBorderBottom(BorderStyle.THIN); //下边框
        cellStyle2.setBorderLeft(BorderStyle.THIN);//左边框
        cellStyle2.setBorderTop(BorderStyle.THIN);//上边框
        cellStyle2.setBorderRight(BorderStyle.THIN);//右边框
        XSSFFont font2 = workbook.createFont();
        font2.setFontName("宋体");
        font2.setFontHeightInPoints((short) 12);
        cellStyle2.setFont(font2);
        Row row2 = ExcelUtil.getRow(sheet, 1);
        row2.setHeightInPoints(20);
        Row row3 = ExcelUtil.getRow(sheet, 2);
        row3.setHeightInPoints(20);
        Cell cell2_0 = ExcelUtil.getCell(row2, 0);
        cell2_0.setCellStyle(cellStyle2);
        cell2_0.setCellValue("序号");
        Cell cell2_1 = ExcelUtil.getCell(row2, 1);
        cell2_1.setCellStyle(cellStyle2);
        cell2_1.setCellValue("名称");
        Cell cell2_2 = ExcelUtil.getCell(row2, 2);
        cell2_2.setCellStyle(cellStyle2);
        cell2_2.setCellValue("模号");
        Cell cell2_3 = ExcelUtil.getCell(row2, 3);
        cell2_3.setCellStyle(cellStyle2);
        cell2_3.setCellValue("技术通\n知单号");
        Cell cell2_4 = ExcelUtil.getCell(row2, 4);
        cell2_4.setCellStyle(cellStyle2);
        cell2_4.setCellValue("产品尺技术通知单");
        Cell cell2_5 = ExcelUtil.getCell(row2, 5);
        cell2_5.setCellStyle(cellStyle2);
        cell2_5.setCellValue("设变内容");
        Cell cell2_6 = ExcelUtil.getCell(row2, 6);
        cell2_6.setCellStyle(cellStyle2);
        cell2_6.setCellValue("设变时间");
        Cell cell2_7 = ExcelUtil.getCell(row2, 7);
        cell2_7.setCellStyle(cellStyle2);
        cell2_7.setCellValue("材料费用");
        Cell cell3_7 = ExcelUtil.getCell(row3, 7);
        cell3_7.setCellStyle(cellStyle2);
        cell3_7.setCellValue("电极");
        Cell cell3_8 = ExcelUtil.getCell(row3, 8);
        cell3_8.setCellStyle(cellStyle2);
        cell3_8.setCellValue("关键件");
        Cell cell3_9 = ExcelUtil.getCell(row3, 9);
        cell3_9.setCellStyle(cellStyle2);
        cell3_9.setCellValue("标准件");
        Cell cell2_10 = ExcelUtil.getCell(row2, 10);
        cell2_10.setCellStyle(cellStyle2);
        cell2_10.setCellValue("制造加工成本目标价");
        Cell cell3_10 = ExcelUtil.getCell(row3, 10);
        cell3_10.setCellStyle(cellStyle2);
        cell3_10.setCellValue("外协费");
        Cell cell3_11 = ExcelUtil.getCell(row3, 11);
        cell3_11.setCellStyle(cellStyle2);
        cell3_11.setCellValue("自制费");
        Cell cell2_12 = ExcelUtil.getCell(row2, 12);
        cell2_12.setCellStyle(cellStyle2);
        cell2_12.setCellValue("设计费用");
        Cell cell2_13 = ExcelUtil.getCell(row2, 13);
        cell2_13.setCellStyle(cellStyle2);
        cell2_13.setCellValue("编程费用");
        Cell cell2_14 = ExcelUtil.getCell(row2, 14);
        cell2_14.setCellStyle(cellStyle2);
        cell2_14.setCellValue("包材费用");
        Cell cell2_15 = ExcelUtil.getCell(row2, 15);
        cell2_15.setCellStyle(cellStyle2);
        cell2_15.setCellValue("试模费用");
        Cell cell2_16 = ExcelUtil.getCell(row2, 16);
        cell2_16.setCellStyle(cellStyle2);
        cell2_16.setCellValue("运输费");
        Cell cell2_17 = ExcelUtil.getCell(row2, 17);
        cell2_17.setCellStyle(cellStyle2);
        cell2_17.setCellValue("制造费用");
        Cell cell2_18 = ExcelUtil.getCell(row2, 18);
        cell2_18.setCellStyle(cellStyle2);
        cell2_18.setCellValue("期间费用");
        Cell cell2_19 = ExcelUtil.getCell(row2, 19);
        cell2_19.setCellStyle(cellStyle2);
        cell2_19.setCellValue("最终未含税");
        Cell cell2_20 = ExcelUtil.getCell(row2, 20);
        cell2_20.setCellStyle(cellStyle2);
        cell2_20.setCellValue("目标毛利润");
        Cell cell2_21 = ExcelUtil.getCell(row2, 21);
        cell2_21.setCellStyle(cellStyle2);
        cell2_21.setCellValue("最终工序目标毛利润占比");
        Cell cell2_22 = ExcelUtil.getCell(row2, 22);
        cell2_22.setCellStyle(cellStyle2);
        cell2_22.setCellValue("税负+期间费用（6%）");

        XSSFCellStyle cellStyle3 = workbook.createCellStyle();
        cellStyle3.setAlignment(HorizontalAlignment.CENTER);
        cellStyle3.setVerticalAlignment(VerticalAlignment.CENTER);
        cellStyle3.setWrapText(true);
        cellStyle3.setBorderBottom(BorderStyle.THIN);
        cellStyle3.setBorderLeft(BorderStyle.THIN);
        cellStyle3.setBorderTop(BorderStyle.THIN);
        cellStyle3.setBorderRight(BorderStyle.THIN);
        XSSFFont font3 = workbook.createFont();
        font3.setFontName("宋体");
        font3.setFontHeightInPoints((short) 12);
        cellStyle3.setFont(font3);
        if (size > 0) {
            for (int i = 0; i < size; i++) {
                InnerDesignChangesDetail innerDesignChangesDetail = details.get(i);
                int num = i + 1;
                Row row = ExcelUtil.getRow(sheet, i + 3);
                row.setHeightInPoints(50);
                CellRangeAddress cellRangeAddress_10 = new CellRangeAddress(i + 3, i + 3, 10, 11);
                ExcelUtil.setCellRangeBorderThin(sheet, cellRangeAddress_10);
                sheet.addMergedRegion(cellRangeAddress_10);
                Cell cell_0 = ExcelUtil.getCell(row, 0);
                cell_0.setCellStyle(cellStyle3);
                cell_0.setCellValue(num);
                Cell cell_1 = ExcelUtil.getCell(row, 1);
                cell_1.setCellStyle(cellStyle3);
                cell_1.setCellValue(innerDesignChangesDetail.getMoldName());
                Cell cell_2 = ExcelUtil.getCell(row, 2);
                cell_2.setCellStyle(cellStyle3);
                cell_2.setCellValue(innerDesignChangesDetail.getMoldId());
                Cell cell_3 = ExcelUtil.getCell(row, 3);
                cell_3.setCellStyle(cellStyle3);
                cell_3.setCellValue(innerDesignChangesDetail.getTechnicalNoticeNumber());
                Cell cell_4 = ExcelUtil.getCell(row, 4);
                cell_4.setCellStyle(cellStyle3);
                cell_4.setCellValue(innerDesignChangesDetail.getProductTechnicalNoticeNumber());
                Cell cell_5 = ExcelUtil.getCell(row, 5);
                cell_5.setCellStyle(cellStyle3);
                cell_5.setCellValue(innerDesignChangesDetail.getContent());
                Cell cell_6 = ExcelUtil.getCell(row, 6);
                cell_6.setCellStyle(cellStyle3);
                cell_6.setCellValue(innerDesignChangesDetail.getTime());
                Cell cell_7 = ExcelUtil.getCell(row, 7);
                cell_7.setCellStyle(cellStyle3);
                cell_7.setCellValue(innerDesignChangesDetail.getElectrodeFee());
                Cell cell_8 = ExcelUtil.getCell(row, 8);
                cell_8.setCellStyle(cellStyle3);
                cell_8.setCellValue(innerDesignChangesDetail.getKeyComponentFee());
                Cell cell_9 = ExcelUtil.getCell(row, 9);
                cell_9.setCellStyle(cellStyle3);
                cell_9.setCellValue(innerDesignChangesDetail.getStandardComponentFee());
                Cell cell_10 = ExcelUtil.getCell(row, 10);
                cell_10.setCellStyle(cellStyle3);
                cell_10.setCellValue(innerDesignChangesDetail.getManufactureFee());
//                Cell cell_11 = ExcelUtil.getCell(row, 11);
//                cell_11.setCellStyle(cellStyle3);
//                cell_11.setCellValue(innerDesignChangesDetail.getOuterDesignChangePrice());
                Cell cell_12 = ExcelUtil.getCell(row, 12);
                cell_12.setCellStyle(cellStyle3);
                cell_12.setCellValue(innerDesignChangesDetail.getDesignFee());
                Cell cell_13 = ExcelUtil.getCell(row, 13);
                cell_13.setCellStyle(cellStyle3);
                cell_13.setCellValue(innerDesignChangesDetail.getProgramFee());
                Cell cell_14 = ExcelUtil.getCell(row, 14);
                cell_14.setCellStyle(cellStyle3);
                cell_14.setCellValue(innerDesignChangesDetail.getPackageFee());
                Cell cell_15 = ExcelUtil.getCell(row, 15);
                cell_15.setCellStyle(cellStyle3);
                cell_15.setCellValue(innerDesignChangesDetail.getTryoutFee());
                Cell cell_16 = ExcelUtil.getCell(row, 16);
                cell_16.setCellStyle(cellStyle3);
                cell_16.setCellValue(innerDesignChangesDetail.getTransportFee());
                Cell cell_17 = ExcelUtil.getCell(row, 17);
                cell_17.setCellStyle(cellStyle3);
                cell_17.setCellValue(innerDesignChangesDetail.getManufacturingFee());
                Cell cell_18 = ExcelUtil.getCell(row, 18);
                cell_18.setCellStyle(cellStyle3);
                cell_18.setCellValue(innerDesignChangesDetail.getPeriodFee());
                Cell cell_19 = ExcelUtil.getCell(row, 19);
                cell_19.setCellStyle(cellStyle3);
                cell_19.setCellValue(innerDesignChangesDetail.getPriceWithoutTax());
                Cell cell_20 = ExcelUtil.getCell(row, 20);
                cell_20.setCellStyle(cellStyle3);
                cell_20.setCellValue(innerDesignChangesDetail.getGrossProfit());
                Cell cell_21 = ExcelUtil.getCell(row, 21);
                cell_21.setCellStyle(cellStyle3);
                cell_21.setCellValue(innerDesignChangesDetail.getGrossProfitRatio());
                Cell cell_22 = ExcelUtil.getCell(row, 22);
                cell_22.setCellStyle(cellStyle3);
                cell_22.setCellValue(innerDesignChangesDetail.getTaxAndPeriodFee());

                XSSFSheet detailSheet = workbook.createSheet(num + "");
                exportInnerDesignChangeDetailExcel(workbook, detailSheet, innerDesignChangesDetail);
            }
        } else {
            Row row = ExcelUtil.getRow(sheet, 3);
            row.setHeightInPoints(50);
            CellRangeAddress cellRangeAddress_10 = new CellRangeAddress(3, 3, 10, 11);
            ExcelUtil.setCellRangeBorderThin(sheet, cellRangeAddress_10);
            sheet.addMergedRegion(cellRangeAddress_10);
            Cell cell_0 = ExcelUtil.getCell(row, 0);
            cell_0.setCellStyle(cellStyle3);
            Cell cell_1 = ExcelUtil.getCell(row, 1);
            cell_1.setCellStyle(cellStyle3);
            Cell cell_2 = ExcelUtil.getCell(row, 2);
            cell_2.setCellStyle(cellStyle3);
            Cell cell_3 = ExcelUtil.getCell(row, 3);
            cell_3.setCellStyle(cellStyle3);
            Cell cell_4 = ExcelUtil.getCell(row, 4);
            cell_4.setCellStyle(cellStyle3);
            Cell cell_5 = ExcelUtil.getCell(row, 5);
            cell_5.setCellStyle(cellStyle3);
            Cell cell_6 = ExcelUtil.getCell(row, 6);
            cell_6.setCellStyle(cellStyle3);
            Cell cell_7 = ExcelUtil.getCell(row, 7);
            cell_7.setCellStyle(cellStyle3);
            Cell cell_8 = ExcelUtil.getCell(row, 8);
            cell_8.setCellStyle(cellStyle3);
            Cell cell_9 = ExcelUtil.getCell(row, 9);
            cell_9.setCellStyle(cellStyle3);
            Cell cell_10 = ExcelUtil.getCell(row, 10);
            cell_10.setCellStyle(cellStyle3);
//            Cell cell_11 = ExcelUtil.getCell(row, 11);
//            cell_11.setCellStyle(cellStyle3);
            Cell cell_12 = ExcelUtil.getCell(row, 12);
            cell_12.setCellStyle(cellStyle3);
            Cell cell_13 = ExcelUtil.getCell(row, 13);
            cell_13.setCellStyle(cellStyle3);
            Cell cell_14 = ExcelUtil.getCell(row, 14);
            cell_14.setCellStyle(cellStyle3);
            Cell cell_15 = ExcelUtil.getCell(row, 15);
            cell_15.setCellStyle(cellStyle3);
            Cell cell_16 = ExcelUtil.getCell(row, 16);
            cell_16.setCellStyle(cellStyle3);
            Cell cell_17 = ExcelUtil.getCell(row, 17);
            cell_17.setCellStyle(cellStyle3);
            Cell cell_18 = ExcelUtil.getCell(row, 18);
            cell_18.setCellStyle(cellStyle3);
            Cell cell_19 = ExcelUtil.getCell(row, 19);
            cell_19.setCellStyle(cellStyle3);
            Cell cell_20 = ExcelUtil.getCell(row, 20);
            cell_20.setCellStyle(cellStyle3);
            Cell cell_21 = ExcelUtil.getCell(row, 21);
            cell_21.setCellStyle(cellStyle3);
            Cell cell_22 = ExcelUtil.getCell(row, 22);
            cell_22.setCellStyle(cellStyle3);
        }

        //合计行
        int rowSub = size > 0 ? 3 + size : 4;
        Row row4 = ExcelUtil.getRow(sheet, rowSub);
        row4.setHeightInPoints(36);
        Cell cell_1 = ExcelUtil.getCell(row4, 1);
        cell_1.setCellStyle(cellStyle3);
        cell_1.setCellValue("总价");
        Cell cell4_19 = ExcelUtil.getCell(row4, 19);
        cell4_19.setCellStyle(cellStyle3);
        cell4_19.setCellValue(innerDesignChanges.getTotalPrice());

        try (FileOutputStream fileOutputStream = new FileOutputStream(filePath)) {
            workbook.write(fileOutputStream);
        } catch (IOException e) {
            e.printStackTrace();
        }


        return resultPath;
    }

    /**
     * 填充数据到excel
     *
     * @param moldSelectionId
     * @param response
     * @return
     */
    private String writeExcel1(String moldSelectionId, HttpServletResponse response) throws Exception {
        //查询所有的detail
        List<InnerDesignChangesDetail> details = detailService.list(new LambdaQueryWrapper<InnerDesignChangesDetail>().eq(InnerDesignChangesDetail::getMoldSelectionId, moldSelectionId));
        byte[] bytes = cloneExcel(details.size());
        String rootUrl = keyWord.getFileUrl();
        String resultPath = "file" + File.separator + "内部设变表-" + System.currentTimeMillis() + ".xlsx";
        String filePath = rootUrl + File.separator + resultPath;
        //保存总费用
        BigDecimal totalFee = new BigDecimal("0");
        //总表页
        WriteSheet writeSheet1 = EasyExcel.writerSheet(0).build();
        //数据填充
        try (ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(bytes);
             ExcelWriter excelWriter = EasyExcel.write(filePath).withTemplate(byteArrayInputStream).build()) {
            FillConfig fillConfig = FillConfig.builder().forceNewRow(Boolean.TRUE).build();
            for (int i = 0; i < details.size(); i++) {
                InnerDesignChangesDetail detail = details.get(i);
                List<InnerDesignChangePrice> prices = priceService.list(new LambdaQueryWrapper<InnerDesignChangePrice>().eq(InnerDesignChangePrice::getDesignChangeId, detail.getId()));
                //详情页
                WriteSheet writeSheet = EasyExcel.writerSheet(i + 1).build();
                List<Map<String, Object>> list = new ArrayList<>();
                Map<String, Object> map = new HashMap<>();

                map.put("id", detail.getId());
                map.put("moldName", detail.getMoldName());
                map.put("moldId", detail.getMoldId());
                map.put("technicalNoticeNumber", detail.getTechnicalNoticeNumber());
                map.put("productTechnicalNoticeNumber", detail.getProductTechnicalNoticeNumber());
                map.put("content", detail.getContent());
                map.put("time", detail.getTime());
                map.put("electrodeFee", detail.getElectrodeFee());
                map.put("keyComponentFee", detail.getKeyComponentFee());
                map.put("standardComponentFee", detail.getStandardComponentFee());
                map.put("outsourceFee", detail.getManufactureFee());
                map.put("selfManufactureFee", detail.getManufacturingFee());
                map.put("designFee", detail.getDesignFee());
                map.put("programFee", detail.getProgramFee());
                map.put("packageFee", detail.getPackageFee());
                map.put("tryoutFee", detail.getTryoutFee());
                map.put("transportFee", detail.getTransportFee());
                map.put("manufacturingFee", detail.getManufacturingFee());
                map.put("periodFee", detail.getPeriodFee());
                String priceWithoutTax = detail.getPriceWithoutTax();
                map.put("priceWithoutTax", priceWithoutTax);
                totalFee = totalFee.add(BigdecimalUtil.stringToBigDecimal(priceWithoutTax));
                map.put("grossProfit", detail.getGrossProfit());
                map.put("grossProfitRatio", detail.getGrossProfitRatio());
                map.put("taxAndPeriodFee", detail.getTaxAndPeriodFee());

                map.put("1", detail.getProjectName());
                map.put("2", detail.getMoldName());
                map.put("3", detail.getProductName());
                map.put("4", detail.getMoldId());
                map.put("5", detail.getDesignChangesCode());
                map.put("6", detail.getMoldLength());
                map.put("7", detail.getMoldWidth());
                map.put("8", detail.getMoldHeight());
                map.put("9", detail.getChangedPeriod());
                map.put("10", detail.getPress());
                map.put("11", detail.getContent());
                map.put("12", detail.getRectificationPlan());
                for (int j = 0; j < prices.size(); j++) {
                    InnerDesignChangePrice price = prices.get(j);
                    String per = price.getPrice();
                    String num = price.getNum();
                    String subTotal = price.getTotalPrice();
                    String check = price.getCheckPrice();
                    String brand = price.getSpecification();
                    String length = price.getLength();
                    String width = price.getWidth();
                    String height = price.getHeight();
                    switch (price.getName()) {
                        case "设计": {
                            map.put("13", per);
                            map.put("14", num);
                            map.put("15", subTotal);
                            map.put("16", check);
                            break;
                        }
                        case "编程": {
                            map.put("17", per);
                            map.put("18", num);
                            map.put("19", subTotal);
                            map.put("20", check);
                            break;
                        }
                        case "CAE": {
                            map.put("21", per);
                            map.put("22", num);
                            map.put("23", subTotal);
                            map.put("24", check);
                            break;
                        }
                        case "钳工": {
                            map.put("26", per);
                            map.put("27", num);
                            map.put("28", subTotal);
                            map.put("29", check);
                            break;
                        }
                        case "CNC": {
                            map.put("30", per);
                            map.put("31", num);
                            map.put("32", subTotal);
                            map.put("33", check);
                            break;
                        }
                        case "EDM": {
                            map.put("34", per);
                            map.put("35", num);
                            map.put("36", subTotal);
                            map.put("37", check);
                            break;
                        }
                        case "线切割": {
                            map.put("38", per);
                            map.put("39", num);
                            map.put("40", subTotal);
                            map.put("41", check);
                            break;
                        }
                        case "普加": {
                            map.put("42", per);
                            map.put("43", num);
                            map.put("44", subTotal);
                            map.put("45", check);
                            break;
                        }
                        case "热处理": {
                            map.put("46", per);
                            map.put("47", num);
                            map.put("48", subTotal);
                            map.put("49", check);
                            break;
                        }
                        case "合模机": {
                            map.put("50", per);
                            map.put("51", num);
                            map.put("52", subTotal);
                            map.put("53", check);
                            break;
                        }
                        case "烧焊": {
                            map.put("54", per);
                            map.put("55", num);
                            map.put("56", subTotal);
                            map.put("57", check);
                            break;
                        }
                        case "抛光": {
                            map.put("58", per);
                            map.put("59", num);
                            map.put("60", subTotal);
                            map.put("61", check);
                            break;
                        }
                        case "装配检测": {
                            map.put("63", per);
                            map.put("64", num);
                            map.put("65", subTotal);
                            map.put("67", check);
                            break;
                        }
                        case "1600T": {
                            map.put("68", per);
                            map.put("69", num);
                            map.put("70", subTotal);
                            map.put("72", check);
                            break;
                        }
                        case "汽运": {
                            map.put("73", per);
                            map.put("74", num);
                            map.put("75", subTotal);
                            map.put("76", check);
                            break;
                        }
                        case "空运": {
                            map.put("77", per);
                            map.put("78", num);
                            map.put("79", subTotal);
                            map.put("80", check);
                            break;
                        }
                        case "材料": {
                            map.put("82", brand);
                            map.put("83", per);
                            map.put("84", length);
                            map.put("85", width);
                            map.put("86", height);
                            map.put("87", num);
                            map.put("88", subTotal);
                            map.put("89", check);
                            break;
                        }
                        case "电极": {
                            map.put("90", brand);
                            map.put("91", per);
                            map.put("92", length);
                            map.put("93", width);
                            map.put("94", height);
                            map.put("95", num);
                            map.put("96", subTotal);
                            map.put("97", check);
                            break;
                        }
                        case "标件": {
                            map.put("98", brand);
                            map.put("99", per);
                            map.put("100", length);
                            map.put("101", width);
                            map.put("102", height);
                            map.put("103", num);
                            map.put("104", subTotal);
                            map.put("105", check);
                            break;
                        }
                        case "热流道": {
                            map.put("106", brand);
                            map.put("107", per);
                            map.put("108", length);
                            map.put("109", width);
                            map.put("110", height);
                            map.put("111", num);
                            map.put("112", subTotal);
                            map.put("113", check);
                            break;
                        }
                        case "其他": {
                            map.put("114", brand);
                            map.put("115", per);
                            map.put("116", length);
                            map.put("117", width);
                            map.put("118", height);
                            map.put("119", num);
                            map.put("120", subTotal);
                            map.put("121", check);
                            break;
                        }
                        case "管理费": {
                            map.put("123", num);
                            map.put("124", subTotal);
                            map.put("125", check);
                            break;
                        }
                        case "利润": {
                            map.put("127", num);
                            map.put("142", subTotal);
                            map.put("128", check);
                            break;
                        }
                        case "税收": {
                            map.put("129", num);
                            map.put("130", subTotal);
                            map.put("132", check);
                            break;
                        }
                    }
                }
                map.put("25", detail.getDesignFeeTotal());
                map.put("62", detail.getMachiningFeeTotal());
                map.put("66", detail.getTestFeeTotal());
                map.put("71", detail.getTryoutFeeTotal());
                map.put("81", detail.getTransportFeeTotal());
                map.put("122", detail.getMaterialFeeTotal());
                map.put("131", detail.getOtherFeeTotal());
                map.put("141", detail.getMainFeeCheck());
                map.put("126", detail.getMaterialFeeCheck());
                map.put("137", detail.getTotalFeeCheck());
                map.put("133", detail.getSupplier());
                map.put("134", detail.getBidder());
                map.put("135", detail.getTime());
                map.put("136", detail.getTotalFee());
                map.put("138", detail.getMaker());
                map.put("139", detail.getAuditor());
                map.put("140", detail.getApprover());
                list.add(map);
                excelWriter.fill(list, fillConfig, writeSheet);
                excelWriter.fill(list, fillConfig, writeSheet1);
            }
            Map<String, Object> map = new HashMap<>();
            map.put("totalFee", totalFee);
            excelWriter.fill(map, writeSheet1);
        }
        //输出填充后的文件
//        outputFile(response, targetPath);
        return resultPath;
    }

    /**
     * 将excel数据用输出流输出
     *
     * @param response
     * @param path
     * @return
     */
    private void outputFile(HttpServletResponse response, String path) {
        String fileName = "inner_design_changes_table";
        response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8");
        response.setHeader("Content-Disposition", "attachment;filename=" + fileName + ".xlsx");
        try (OutputStream out = response.getOutputStream()) {
            byte[] bytes = FileUtils.readFileToByteArray(new File(path));
            out.write(bytes);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    @Override
    public String exportOutDesignChange(JSONObject jsonObject, HttpServletResponse response) {
        //jsonobject解析获取选模表Id
        String moldSelectionId = jsonObject.getString("moldSelectionId");
        //jsonobject解析获取是否审批
        String isApprove = jsonObject.getString("isApprove");

        String resultPath = exportOutDesignChangeExcel(moldSelectionId, isApprove);

//        int totalNum = outerDesignChangesDetailList.size();
//        try (InputStream resourceAsStream = getClass().getClassLoader().getResourceAsStream("templates/6_outer_design_changes.xlsx")) {
//            try (XSSFWorkbook sheets = new XSSFWorkbook(resourceAsStream)) {
//                XSSFSheet sheet = sheets.getSheetAt(0);
//                //默认有主表和明细1
//                if (totalNum > 1) {
//                    //明细条数大于1，克隆表格
//                    for (int i = 0; i < totalNum - 1; i++) {
//                        sheets.cloneSheet(1, Integer.toString(i + 2));
//                    }
//                    //增加行
//                    if (totalNum > 3) {
//                        createOuterRow(sheet, 12, totalNum - 3);
//                    }
//                } else if (totalNum == 0) {
//                    //明细条数为0，删除明细1
//                    sheets.removeSheetAt(1);
//                }
//                if (ObjectUtil.isNotNull(outerDesignChanges)) {
//                    setExcel(sheets, outerDesignChanges, outerDesignChangesDetailList);
//                }
//                try (FileOutputStream fileOutputStream = new FileOutputStream(filePath)) {
//                    sheets.write(fileOutputStream);
//                } catch (IOException e) {
//                    e.printStackTrace();
//                }
////                response.setContentType("application/vdn.openxmlformats-officedocument.spreadsheetml.sgeet;charset=utf-8");
////                String filename = URLEncoder.encode("导出表.xlsx", "UTF-8");
////                response.setCharacterEncoding("UTF-8");
////                response.setHeader("Content-disposition", "attachment;filename=" + filename);
////                ServletOutputStream outputStream1 = response.getOutputStream();
////                sheets.write(outputStream1);
////                outputStream1.close();
//            } catch (IOException e) {
//                e.printStackTrace();
//            }
//        } catch (IOException e) {
//            e.printStackTrace();
//        }
        return JSON.toJSONString(R.data("filePath: " + resultPath, "导出成功"));
    }

    private String exportOutDesignChangeExcel(String moldSelectionId, String isApprove) {
        String projectName = iMoldSelectionService.getProjectName(moldSelectionId);
        String resultPath = "file" + File.separator + projectName + "项目-外部设变表-" + DateUtils.dateTimeNow("yyyyMMdd-SSS") + ".xlsx";
        String filePath = keyWord.getFileUrl() + File.separator + resultPath;

        OuterDesignChanges outerDesignChanges = outerDesignChangesMapper
                .selectOne(new LambdaQueryWrapper<OuterDesignChanges>()
                        .eq(OuterDesignChanges::getMoldSelectionId, moldSelectionId));
        List<OuterDesignChangesDetail> outerDesignChangesDetailList = outerDesignChangesDetailMapper
                .selectList(new LambdaQueryWrapper<OuterDesignChangesDetail>()
                        .eq(OuterDesignChangesDetail::getMoldSelectionId, moldSelectionId)
                        .eq(StringUtils.isNotEmpty(isApprove), OuterDesignChangesDetail::getIsApprove, isApprove));
        int rowSize = outerDesignChangesDetailList.size();
        //创建一个工作簿
        XSSFWorkbook workbook = new XSSFWorkbook();
        //总表
        XSSFSheet sheet = workbook.createSheet("设变统计总表");
        //列宽
        sheet.setColumnWidth(0, 6 * 256);
        sheet.setColumnWidth(1, 15 * 256);
        sheet.setColumnWidth(2, 15 * 256);
        sheet.setColumnWidth(3, 15 * 256);
        sheet.setColumnWidth(4, 15 * 256);
        sheet.setColumnWidth(5, 50 * 256);
        sheet.setColumnWidth(6, 20 * 256);
        sheet.setColumnWidth(7, 20 * 256);
        sheet.setColumnWidth(8, 20 * 256);
        sheet.setColumnWidth(9, 15 * 256);
        sheet.setColumnWidth(10, 15 * 256);
        sheet.setColumnWidth(11, 15 * 256);
        sheet.setColumnWidth(12, 15 * 256);
        sheet.setColumnWidth(13, 15 * 256);
        sheet.setColumnWidth(14, 15 * 256);

        //第一行
        CellRangeAddress cellRangeAddress0 = new CellRangeAddress(0, 0, 0, 14);
        ExcelUtil.setCellRangeBorderThin(sheet, cellRangeAddress0);
        sheet.addMergedRegion(cellRangeAddress0);
        XSSFCellStyle cellStyle0 = workbook.createCellStyle();
        cellStyle0.setAlignment(HorizontalAlignment.LEFT);
        cellStyle0.setVerticalAlignment(VerticalAlignment.CENTER);
        cellStyle0.setWrapText(true);
        cellStyle0.setBorderBottom(BorderStyle.THIN); //下边框
        cellStyle0.setBorderLeft(BorderStyle.THIN);//左边框
        cellStyle0.setBorderTop(BorderStyle.THIN);//上边框
        cellStyle0.setBorderRight(BorderStyle.THIN);//右边框
        XSSFFont font0 = workbook.createFont();
        font0.setFontName("黑体");
        font0.setFontHeightInPoints((short) 12);
        cellStyle0.setFont(font0);
        Row row0 = ExcelUtil.getRow(sheet, 0);
        row0.setHeightInPoints(240);
        Cell cell0 = ExcelUtil.getCell(row0, 0);
        cell0.setCellStyle(cellStyle0);
        String row0Value = "\n填写要求：\n" +
                "1、上表中除最后3列外，其余列均由项目组填写；\n" +
                "2、每套模具的所有设变排在一起，并且模具名称及模具编号合并（如上表格）；\n" +
                "3、模具编号必须填写我公司的模具编号；\n" +
                "4、同一家模具供应商的模具设变排放在一起；\n" +
                "5、填入此表中的设变均是需要给模具供应商支付设变费用的设变；\n" +
                "6、当同1张技术通知中含多次设变内容，而且每次设变模具都是按设变流程走完了的（设计、加工、装拆模、试模、交件等），填写时需要合并技术通知单单号及技术通知单，而设变内容分开填写（如下5、6项的填写）；\n" +
                "7、表中的序号必须与提供的报价明细一一对应；\n" +
                "8、报价明细中必须填写模具实际设变方案（该方案是在模具上已经执行了的），方案需要有图片说明；\n" +
                "9、当设变执行完后，需要打样送件时，请在报价明细中写明件是从哪里送到哪里，多少件，什么样的运送方式（空运、陆运或其他特殊方式等）；\n" +
                "10、报价明细中的“烧焊”项的内容必须在方案写明烧焊方式（氩弧焊、激光焊或其他焊接方式）及烧焊面积；\n" +
                "11、报价明细中的“线切割”项的内容必须在方案写明线切割方式（慢走丝还快走丝）；\n" +
                "12、所有的设变报价明细必须按我司提供的表填写，不能改动我司提供报价明细表；";
        cell0.setCellValue(row0Value);

        //第二行
        CellRangeAddress cellRangeAddress1 = new CellRangeAddress(1, 1, 0, 14);
        ExcelUtil.setCellRangeBorderThin(sheet, cellRangeAddress1);
        sheet.addMergedRegion(cellRangeAddress1);
        //单元格格式
        XSSFCellStyle cellStyle1 = workbook.createCellStyle();
        cellStyle1.setAlignment(HorizontalAlignment.CENTER);
        cellStyle1.setVerticalAlignment(VerticalAlignment.CENTER);
        cellStyle1.setBorderBottom(BorderStyle.THIN);
        cellStyle1.setBorderLeft(BorderStyle.THIN);
        cellStyle1.setBorderTop(BorderStyle.THIN);
        cellStyle1.setBorderRight(BorderStyle.THIN);
        XSSFFont font1 = workbook.createFont();
        font1.setFontName("黑体");
        font1.setFontHeightInPoints((short) 36);
        cellStyle1.setFont(font1);
        Row row1 = ExcelUtil.getRow(sheet, 1);
        row1.setHeightInPoints(50);
        Cell cell1 = ExcelUtil.getCell(row1, 0);
        cell1.setCellStyle(cellStyle1);
        cell1.setCellValue("项目设变目标价审批表");

        //第三行
        CellRangeAddress cellRangeAddress2_0 = new CellRangeAddress(2, 3, 0, 0);
        ExcelUtil.setCellRangeBorderThin(sheet, cellRangeAddress2_0);
        sheet.addMergedRegion(cellRangeAddress2_0);
        CellRangeAddress cellRangeAddress2_1 = new CellRangeAddress(2, 3, 1, 1);
        ExcelUtil.setCellRangeBorderThin(sheet, cellRangeAddress2_1);
        sheet.addMergedRegion(cellRangeAddress2_1);
        CellRangeAddress cellRangeAddress2_2 = new CellRangeAddress(2, 3, 2, 2);
        ExcelUtil.setCellRangeBorderThin(sheet, cellRangeAddress2_2);
        sheet.addMergedRegion(cellRangeAddress2_2);
        CellRangeAddress cellRangeAddress2_3 = new CellRangeAddress(2, 3, 3, 3);
        ExcelUtil.setCellRangeBorderThin(sheet, cellRangeAddress2_3);
        sheet.addMergedRegion(cellRangeAddress2_3);
        CellRangeAddress cellRangeAddress2_4 = new CellRangeAddress(2, 3, 4, 4);
        ExcelUtil.setCellRangeBorderThin(sheet, cellRangeAddress2_4);
        sheet.addMergedRegion(cellRangeAddress2_4);
        CellRangeAddress cellRangeAddress2_5 = new CellRangeAddress(2, 3, 5, 5);
        ExcelUtil.setCellRangeBorderThin(sheet, cellRangeAddress2_5);
        sheet.addMergedRegion(cellRangeAddress2_5);
        CellRangeAddress cellRangeAddress2_6 = new CellRangeAddress(2, 3, 6, 6);
        ExcelUtil.setCellRangeBorderThin(sheet, cellRangeAddress2_6);
        sheet.addMergedRegion(cellRangeAddress2_6);
        CellRangeAddress cellRangeAddress2_7 = new CellRangeAddress(2, 3, 7, 7);
        ExcelUtil.setCellRangeBorderThin(sheet, cellRangeAddress2_7);
        sheet.addMergedRegion(cellRangeAddress2_7);
        CellRangeAddress cellRangeAddress2_8 = new CellRangeAddress(2, 3, 8, 8);
        ExcelUtil.setCellRangeBorderThin(sheet, cellRangeAddress2_8);
        sheet.addMergedRegion(cellRangeAddress2_8);
        CellRangeAddress cellRangeAddress2_9 = new CellRangeAddress(2, 3, 9, 9);
        ExcelUtil.setCellRangeBorderThin(sheet, cellRangeAddress2_9);
        sheet.addMergedRegion(cellRangeAddress2_9);
        CellRangeAddress cellRangeAddress2_10 = new CellRangeAddress(2, 3, 10, 10);
        ExcelUtil.setCellRangeBorderThin(sheet, cellRangeAddress2_10);
        sheet.addMergedRegion(cellRangeAddress2_10);
        CellRangeAddress cellRangeAddress2_11 = new CellRangeAddress(2, 2, 11, 12);
        ExcelUtil.setCellRangeBorderThin(sheet, cellRangeAddress2_11);
        sheet.addMergedRegion(cellRangeAddress2_11);
        CellRangeAddress cellRangeAddress2_12 = new CellRangeAddress(2, 3, 13, 13);
        ExcelUtil.setCellRangeBorderThin(sheet, cellRangeAddress2_12);
        sheet.addMergedRegion(cellRangeAddress2_12);
        CellRangeAddress cellRangeAddress2_13 = new CellRangeAddress(2, 3, 14, 14);
        ExcelUtil.setCellRangeBorderThin(sheet, cellRangeAddress2_13);
        sheet.addMergedRegion(cellRangeAddress2_13);
        XSSFCellStyle cellStyle2 = workbook.createCellStyle();
        cellStyle2.setAlignment(HorizontalAlignment.CENTER);
        cellStyle2.setVerticalAlignment(VerticalAlignment.CENTER);
        cellStyle2.setWrapText(true);
        cellStyle2.setBorderBottom(BorderStyle.THIN); //下边框
        cellStyle2.setBorderLeft(BorderStyle.THIN);//左边框
        cellStyle2.setBorderTop(BorderStyle.THIN);//上边框
        cellStyle2.setBorderRight(BorderStyle.THIN);//右边框
        XSSFFont font2 = workbook.createFont();
        font2.setFontName("黑体");
        font2.setFontHeightInPoints((short) 16);
        cellStyle2.setFont(font2);
        Row row2 = ExcelUtil.getRow(sheet, 2);
        row2.setHeightInPoints(36);
        Cell cell2_0 = ExcelUtil.getCell(row2, 0);
        cell2_0.setCellStyle(cellStyle2);
        cell2_0.setCellValue("序号");
        Cell cell2_1 = ExcelUtil.getCell(row2, 1);
        cell2_1.setCellStyle(cellStyle2);
        cell2_1.setCellValue("模具名称");
        Cell cell2_2 = ExcelUtil.getCell(row2, 2);
        cell2_2.setCellStyle(cellStyle2);
        cell2_2.setCellValue("模具编号");
        Cell cell2_3 = ExcelUtil.getCell(row2, 3);
        cell2_3.setCellStyle(cellStyle2);
        cell2_3.setCellValue("技术通\n知单号");
        Cell cell2_4 = ExcelUtil.getCell(row2, 4);
        cell2_4.setCellStyle(cellStyle2);
        cell2_4.setCellValue("技术通知单");
        Cell cell2_5 = ExcelUtil.getCell(row2, 5);
        cell2_5.setCellStyle(cellStyle2);
        cell2_5.setCellValue("设变内容");
        Cell cell2_6 = ExcelUtil.getCell(row2, 6);
        cell2_6.setCellStyle(cellStyle2);
        cell2_6.setCellValue("设变时间");
        Cell cell2_7 = ExcelUtil.getCell(row2, 7);
        cell2_7.setCellStyle(cellStyle2);
        cell2_7.setCellValue("设变来源");
        Cell cell2_8 = ExcelUtil.getCell(row2, 8);
        cell2_8.setCellStyle(cellStyle2);
        cell2_8.setCellValue("设变类别");
        Cell cell2_9 = ExcelUtil.getCell(row2, 9);
        cell2_9.setCellStyle(cellStyle2);
        cell2_9.setCellValue("模具\n供应商");
        Cell cell2_10 = ExcelUtil.getCell(row2, 10);
        cell2_10.setCellStyle(cellStyle2);
        cell2_10.setCellValue("供应商报价(含税元)");
        Cell cell2_11 = ExcelUtil.getCell(row2, 11);
        cell2_11.setCellStyle(cellStyle2);
        cell2_11.setCellValue("目标价(含税元)");
        Cell cell2_13 = ExcelUtil.getCell(row2, 13);
        cell2_13.setCellStyle(cellStyle2);
        cell2_13.setCellValue("模具费用（含税元）");
        Cell cell2_14 = ExcelUtil.getCell(row2, 14);
        cell2_14.setCellStyle(cellStyle2);
        cell2_14.setCellValue("设变目标价占比");
        Row row3 = ExcelUtil.getRow(sheet, 3);
        row3.setHeightInPoints(36);
        Cell cell3_11 = ExcelUtil.getCell(row3, 11);
        cell3_11.setCellStyle(cellStyle2);
        cell3_11.setCellValue("客户");
        Cell cell3_12 = ExcelUtil.getCell(row3, 12);
        cell3_12.setCellStyle(cellStyle2);
        cell3_12.setCellValue("内部");

        //列表行
        XSSFCellStyle cellStyle3 = workbook.createCellStyle();
        cellStyle3.setAlignment(HorizontalAlignment.CENTER);
        cellStyle3.setVerticalAlignment(VerticalAlignment.CENTER);
        cellStyle3.setWrapText(true);
        cellStyle3.setBorderBottom(BorderStyle.THIN);
        cellStyle3.setBorderLeft(BorderStyle.THIN);
        cellStyle3.setBorderTop(BorderStyle.THIN);
        cellStyle3.setBorderRight(BorderStyle.THIN);
        XSSFFont font3 = workbook.createFont();
        font3.setFontName("黑体");
        font3.setFontHeightInPoints((short) 14);
        cellStyle3.setFont(font3);
        if (rowSize > 0) {
            for (int i = 0; i < rowSize; i++) {
                OuterDesignChangesDetail outerDesignChangesDetail = outerDesignChangesDetailList.get(i);
                int num = i + 1;
                Row row = ExcelUtil.getRow(sheet, i + 4);
                row.setHeightInPoints(72);
                Cell cell_0 = ExcelUtil.getCell(row, 0);
                cell_0.setCellStyle(cellStyle3);
                cell_0.setCellValue(num);
                Cell cell_1 = ExcelUtil.getCell(row, 1);
                cell_1.setCellStyle(cellStyle3);
                cell_1.setCellValue(outerDesignChangesDetail.getMoldName());
                Cell cell_2 = ExcelUtil.getCell(row, 2);
                cell_2.setCellStyle(cellStyle3);
                cell_2.setCellValue(outerDesignChangesDetail.getMoldId());
                Cell cell_3 = ExcelUtil.getCell(row, 3);
                cell_3.setCellStyle(cellStyle3);
                cell_3.setCellValue(outerDesignChangesDetail.getTechnicalNoticeNumber());
                Cell cell_4 = ExcelUtil.getCell(row, 4);
                cell_4.setCellStyle(cellStyle3);
                cell_4.setCellValue(outerDesignChangesDetail.getProductTechnicalNoticeNumber());
                Cell cell_5 = ExcelUtil.getCell(row, 5);
                cell_5.setCellStyle(cellStyle3);
                cell_5.setCellValue(outerDesignChangesDetail.getContent());
                Cell cell_6 = ExcelUtil.getCell(row, 6);
                cell_6.setCellStyle(cellStyle3);
                cell_6.setCellValue(outerDesignChangesDetail.getTime());
                Cell cell_7 = ExcelUtil.getCell(row, 7);
                cell_7.setCellStyle(cellStyle3);
                String source = outerDesignChangesDetail.getSource();
                switch (source) {
                    case "1":
                        cell_7.setCellValue("内部设变");
                        break;
                    case "2":
                        cell_7.setCellValue("客户设变");
                        break;
                }
                Cell cell_8 = ExcelUtil.getCell(row, 8);
                cell_8.setCellStyle(cellStyle3);
                cell_8.setCellValue(outerDesignChangesDetail.getType());
                Cell cell_9 = ExcelUtil.getCell(row, 9);
                cell_9.setCellStyle(cellStyle3);
                final String supplier = outerDesignChangesDetail.getSupplier();
                if (StringUtils.isNotEmpty(supplier)) {
                    final DictTable dictTable = dictTableMapper.selectOne(new LambdaQueryWrapper<DictTable>().eq(DictTable::getDicId, supplier));
                    if (ObjectUtil.isNotEmpty(dictTable)) {
                        cell_9.setCellValue(dictTable.getDicName());
                    }
                }
                Cell cell_10 = ExcelUtil.getCell(row, 10);
                cell_10.setCellStyle(cellStyle3);
                cell_10.setCellValue(outerDesignChangesDetail.getSupplierFee());
                Cell cell_11 = ExcelUtil.getCell(row, 11);
                cell_11.setCellStyle(cellStyle3);
                cell_11.setCellValue(outerDesignChangesDetail.getOuterDesignChangePrice());
                Cell cell_12 = ExcelUtil.getCell(row, 12);
                cell_12.setCellStyle(cellStyle3);
                cell_12.setCellValue(outerDesignChangesDetail.getInnerDesignChangePrice());
                Cell cell_13 = ExcelUtil.getCell(row, 13);
                cell_13.setCellStyle(cellStyle3);
                cell_13.setCellValue(outerDesignChangesDetail.getMoldPrice());
                Cell cell_14 = ExcelUtil.getCell(row, 14);
                cell_14.setCellStyle(cellStyle3);
                cell_14.setCellValue(outerDesignChangesDetail.getDesignChangeRatio());

                XSSFSheet detailSheet = workbook.createSheet(num + "");
                exportOutDesignChangeDetailExcel(workbook, detailSheet, outerDesignChangesDetail);
            }
        } else {
            Row row = ExcelUtil.getRow(sheet, 4);
            row.setHeightInPoints(72);
            Cell cell_0 = ExcelUtil.getCell(row, 0);
            cell_0.setCellStyle(cellStyle3);
            Cell cell_1 = ExcelUtil.getCell(row, 1);
            cell_1.setCellStyle(cellStyle3);
            Cell cell_2 = ExcelUtil.getCell(row, 2);
            cell_2.setCellStyle(cellStyle3);
            Cell cell_3 = ExcelUtil.getCell(row, 3);
            cell_3.setCellStyle(cellStyle3);
            Cell cell_4 = ExcelUtil.getCell(row, 4);
            cell_4.setCellStyle(cellStyle3);
            Cell cell_5 = ExcelUtil.getCell(row, 5);
            cell_5.setCellStyle(cellStyle3);
            Cell cell_6 = ExcelUtil.getCell(row, 6);
            cell_6.setCellStyle(cellStyle3);
            Cell cell_7 = ExcelUtil.getCell(row, 7);
            cell_7.setCellStyle(cellStyle3);
            Cell cell_8 = ExcelUtil.getCell(row, 8);
            cell_8.setCellStyle(cellStyle3);
            Cell cell_9 = ExcelUtil.getCell(row, 9);
            cell_9.setCellStyle(cellStyle3);
            Cell cell_10 = ExcelUtil.getCell(row, 10);
            cell_10.setCellStyle(cellStyle3);
            Cell cell_11 = ExcelUtil.getCell(row, 11);
            cell_11.setCellStyle(cellStyle3);
            Cell cell_12 = ExcelUtil.getCell(row, 12);
            cell_12.setCellStyle(cellStyle3);
            Cell cell_13 = ExcelUtil.getCell(row, 13);
            cell_13.setCellStyle(cellStyle3);
            Cell cell_14 = ExcelUtil.getCell(row, 14);
            cell_14.setCellStyle(cellStyle3);
        }

        //合计行
        int rowSub = rowSize > 0 ? 4 + rowSize : 5;
        CellRangeAddress cellRangeAddress5 = new CellRangeAddress(rowSub, rowSub, 0, 9);
        ExcelUtil.setCellRangeBorderThin(sheet, cellRangeAddress5);
        sheet.addMergedRegion(cellRangeAddress5);
        XSSFCellStyle cellStyle5_0 = workbook.createCellStyle();
        cellStyle5_0.setAlignment(HorizontalAlignment.RIGHT);
        cellStyle5_0.setVerticalAlignment(VerticalAlignment.CENTER);
        cellStyle5_0.setBorderBottom(BorderStyle.THIN);
        cellStyle5_0.setBorderLeft(BorderStyle.THIN);
        cellStyle5_0.setBorderTop(BorderStyle.THIN);
        cellStyle5_0.setBorderRight(BorderStyle.THIN);
        XSSFFont font5_0 = workbook.createFont();
        font5_0.setFontName("黑体");
        font5_0.setFontHeightInPoints((short) 22);
        cellStyle5_0.setFont(font5_0);
        XSSFCellStyle cellStyle5_1 = workbook.createCellStyle();
        cellStyle5_1.setAlignment(HorizontalAlignment.CENTER);
        cellStyle5_1.setVerticalAlignment(VerticalAlignment.CENTER);
        cellStyle5_1.setBorderBottom(BorderStyle.THIN);
        cellStyle5_1.setBorderLeft(BorderStyle.THIN);
        cellStyle5_1.setBorderTop(BorderStyle.THIN);
        cellStyle5_1.setBorderRight(BorderStyle.THIN);
        XSSFFont font5_1 = workbook.createFont();
        font5_1.setFontName("黑体");
        font5_1.setFontHeightInPoints((short) 18);
        cellStyle5_1.setFont(font5_1);
        Row row5 = ExcelUtil.getRow(sheet, rowSub);
        row5.setHeightInPoints(39);
        Cell cell5_0 = ExcelUtil.getCell(row5, 0);
        cell5_0.setCellStyle(cellStyle5_0);
        cell5_0.setCellValue("合计：");
        Cell cell5_10 = ExcelUtil.getCell(row5, 10);
        cell5_10.setCellStyle(cellStyle5_1);
        Cell cell5_11 = ExcelUtil.getCell(row5, 11);
        cell5_11.setCellStyle(cellStyle5_1);
        Cell cell5_12 = ExcelUtil.getCell(row5, 12);
        cell5_12.setCellStyle(cellStyle5_1);
        Cell cell5_13 = ExcelUtil.getCell(row5, 13);
        cell5_13.setCellStyle(cellStyle5_1);
        Cell cell5_14 = ExcelUtil.getCell(row5, 14);
        cell5_14.setCellStyle(cellStyle5_1);

        if (ObjectUtil.isNull(outerDesignChanges)) {
            cell5_10.setCellValue("0.00");
            cell5_11.setCellValue("0.00");
            cell5_12.setCellValue("0.00");
        } else {
            cell5_10.setCellValue(outerDesignChanges.getSupplierFeeTotal());
            cell5_11.setCellValue(outerDesignChanges.getOuterDesignChangePrice());
            cell5_12.setCellValue(outerDesignChanges.getInnerDesignChangePrice());
        }

        //项目模具总费用
        CellRangeAddress cellRangeAddress6_0 = new CellRangeAddress(rowSub + 1, rowSub + 2, 0, 4);
        ExcelUtil.setCellRangeBorderThin(sheet, cellRangeAddress6_0);
        RegionUtil.setBorderTop(BorderStyle.MEDIUM, cellRangeAddress6_0, sheet);
        RegionUtil.setBorderLeft(BorderStyle.MEDIUM, cellRangeAddress6_0, sheet);
        sheet.addMergedRegion(cellRangeAddress6_0);
        CellRangeAddress cellRangeAddress6_1 = new CellRangeAddress(rowSub + 1, rowSub + 1, 5, 8);
        ExcelUtil.setCellRangeBorderThin(sheet, cellRangeAddress6_1);
        RegionUtil.setBorderTop(BorderStyle.MEDIUM, cellRangeAddress6_1, sheet);
        sheet.addMergedRegion(cellRangeAddress6_1);
        CellRangeAddress cellRangeAddress6_2 = new CellRangeAddress(rowSub + 1, rowSub + 1, 9, 14);
        ExcelUtil.setCellRangeBorderThin(sheet, cellRangeAddress6_2);
        RegionUtil.setBorderTop(BorderStyle.MEDIUM, cellRangeAddress6_2, sheet);
        RegionUtil.setBorderRight(BorderStyle.MEDIUM, cellRangeAddress6_2, sheet);
        sheet.addMergedRegion(cellRangeAddress6_2);
        XSSFCellStyle cellStyle6 = workbook.createCellStyle();
        cellStyle6.setAlignment(HorizontalAlignment.CENTER);
        cellStyle6.setVerticalAlignment(VerticalAlignment.CENTER);
        cellStyle6.setBorderBottom(BorderStyle.THIN);
        cellStyle6.setBorderLeft(BorderStyle.THIN);
        cellStyle6.setBorderTop(BorderStyle.MEDIUM);
        cellStyle6.setBorderRight(BorderStyle.THIN);
        XSSFFont font6_0 = workbook.createFont();
        font6_0.setFontName("黑体");
        font6_0.setFontHeightInPoints((short) 20);
        cellStyle6.setFont(font6_0);
        Row row6 = ExcelUtil.getRow(sheet, rowSub + 1);
        row6.setHeightInPoints(50);
        Cell cell6_0 = ExcelUtil.getCell(row6, 0);
        cell6_0.setCellStyle(cellStyle6);
        cell6_0.setCellValue("项目模具总费用（含税元）");
        Cell cell6_1 = ExcelUtil.getCell(row6, 5);
        cell6_1.setCellStyle(cellStyle6);
        cell6_1.setCellValue("设变目标价费用（含税元）");
        Cell cell6_2 = ExcelUtil.getCell(row6, 9);
        cell6_2.setCellStyle(cellStyle6);
        cell6_2.setCellValue("设变目标价占总模具费用比例");

        CellRangeAddress cellRangeAddress7_1 = new CellRangeAddress(rowSub + 2, rowSub + 2, 5, 6);
        ExcelUtil.setCellRangeBorderThin(sheet, cellRangeAddress7_1);
        sheet.addMergedRegion(cellRangeAddress7_1);
        CellRangeAddress cellRangeAddress7_2 = new CellRangeAddress(rowSub + 2, rowSub + 2, 7, 8);
        ExcelUtil.setCellRangeBorderThin(sheet, cellRangeAddress7_2);
        sheet.addMergedRegion(cellRangeAddress7_2);
        CellRangeAddress cellRangeAddress7_3 = new CellRangeAddress(rowSub + 2, rowSub + 2, 9, 11);
        ExcelUtil.setCellRangeBorderThin(sheet, cellRangeAddress7_3);
        sheet.addMergedRegion(cellRangeAddress7_3);
        CellRangeAddress cellRangeAddress7_4 = new CellRangeAddress(rowSub + 2, rowSub + 2, 12, 14);
        ExcelUtil.setCellRangeBorderThin(sheet, cellRangeAddress7_4);
        RegionUtil.setBorderRight(BorderStyle.MEDIUM, cellRangeAddress7_4, sheet);
        sheet.addMergedRegion(cellRangeAddress7_4);
        XSSFCellStyle cellStyle7 = workbook.createCellStyle();
        cellStyle7.setAlignment(HorizontalAlignment.CENTER);
        cellStyle7.setVerticalAlignment(VerticalAlignment.CENTER);
        cellStyle7.setBorderBottom(BorderStyle.THIN);
        cellStyle7.setBorderLeft(BorderStyle.THIN);
        cellStyle7.setBorderTop(BorderStyle.THIN);
        cellStyle7.setBorderRight(BorderStyle.THIN);
        XSSFFont font7 = workbook.createFont();
        font7.setFontName("黑体");
        font7.setFontHeightInPoints((short) 20);
        cellStyle7.setFont(font7);
        Row row7 = ExcelUtil.getRow(sheet, rowSub + 2);
        row7.setHeightInPoints(50);
        Cell cell7_1 = ExcelUtil.getCell(row7, 5);
        cell7_1.setCellStyle(cellStyle7);
        cell7_1.setCellValue("客户设变费用");
        Cell cell7_2 = ExcelUtil.getCell(row7, 7);
        cell7_2.setCellStyle(cellStyle7);
        cell7_2.setCellValue("内部设变费用");
        Cell cell7_3 = ExcelUtil.getCell(row7, 9);
        cell7_3.setCellStyle(cellStyle7);
        cell7_3.setCellValue("客户设变占比");
        Cell cell7_4 = ExcelUtil.getCell(row7, 12);
        cell7_4.setCellStyle(cellStyle7);
        cell7_4.setCellValue("内部设变占比");

        CellRangeAddress cellRangeAddress8_0 = new CellRangeAddress(rowSub + 3, rowSub + 3, 0, 4);
        ExcelUtil.setCellRangeBorderThin(sheet, cellRangeAddress8_0);
        RegionUtil.setBorderLeft(BorderStyle.MEDIUM, cellRangeAddress8_0, sheet);
        sheet.addMergedRegion(cellRangeAddress8_0);
        CellRangeAddress cellRangeAddress8_1 = new CellRangeAddress(rowSub + 3, rowSub + 3, 5, 6);
        ExcelUtil.setCellRangeBorderThin(sheet, cellRangeAddress8_1);
        sheet.addMergedRegion(cellRangeAddress8_1);
        CellRangeAddress cellRangeAddress8_2 = new CellRangeAddress(rowSub + 3, rowSub + 3, 7, 8);
        ExcelUtil.setCellRangeBorderThin(sheet, cellRangeAddress8_2);
        sheet.addMergedRegion(cellRangeAddress8_2);
        CellRangeAddress cellRangeAddress8_3 = new CellRangeAddress(rowSub + 3, rowSub + 3, 9, 11);
        ExcelUtil.setCellRangeBorderThin(sheet, cellRangeAddress8_3);
        sheet.addMergedRegion(cellRangeAddress8_3);
        CellRangeAddress cellRangeAddress8_4 = new CellRangeAddress(rowSub + 3, rowSub + 3, 12, 14);
        ExcelUtil.setCellRangeBorderThin(sheet, cellRangeAddress8_4);
        RegionUtil.setBorderRight(BorderStyle.MEDIUM, cellRangeAddress8_4, sheet);
        sheet.addMergedRegion(cellRangeAddress8_4);
        XSSFCellStyle cellStyle8 = workbook.createCellStyle();
        cellStyle8.setAlignment(HorizontalAlignment.CENTER);
        cellStyle8.setVerticalAlignment(VerticalAlignment.CENTER);
        cellStyle8.setWrapText(true);
        cellStyle8.setBorderBottom(BorderStyle.THIN);
        cellStyle8.setBorderLeft(BorderStyle.THIN);
        cellStyle8.setBorderTop(BorderStyle.THIN);
        cellStyle8.setBorderRight(BorderStyle.THIN);
        XSSFFont font8 = workbook.createFont();
        font8.setFontName("黑体");
        font8.setFontHeightInPoints((short) 18);
        cellStyle8.setFont(font8);
        Row row8 = ExcelUtil.getRow(sheet, rowSub + 3);
        row8.setHeightInPoints(36);
        Cell cell8_0 = ExcelUtil.getCell(row8, 0);
        cell8_0.setCellStyle(cellStyle8);
        Cell cell8_1 = ExcelUtil.getCell(row8, 5);
        cell8_1.setCellStyle(cellStyle8);
        Cell cell8_2 = ExcelUtil.getCell(row8, 7);
        cell8_2.setCellStyle(cellStyle8);
        Cell cell8_3 = ExcelUtil.getCell(row8, 9);
        cell8_3.setCellStyle(cellStyle8);
        Cell cell8_4 = ExcelUtil.getCell(row8, 12);
        cell8_4.setCellStyle(cellStyle8);
        if (ObjectUtil.isNull(outerDesignChanges)) {
            cell8_0.setCellValue("0.00");
            cell8_1.setCellValue("0.00");
            cell8_2.setCellValue("0.00");
        } else {
            cell8_0.setCellValue(outerDesignChanges.getMoldTotalPrice());
            cell8_1.setCellValue(outerDesignChanges.getOuterDesignChangePrice());
            cell8_2.setCellValue(outerDesignChanges.getInnerDesignChangePrice());
            cell8_3.setCellValue(outerDesignChanges.getOuterDesignChangeRatio() + "%");
            cell8_4.setCellValue(outerDesignChanges.getInnerDesignChangeRatio() + "%");
        }

        CellRangeAddress cellRangeAddress9_0 = new CellRangeAddress(rowSub + 4, rowSub + 4, 0, 4);
        ExcelUtil.setCellRangeBorderThin(sheet, cellRangeAddress9_0);
        RegionUtil.setBorderLeft(BorderStyle.MEDIUM, cellRangeAddress9_0, sheet);
        sheet.addMergedRegion(cellRangeAddress9_0);
        CellRangeAddress cellRangeAddress9_1 = new CellRangeAddress(rowSub + 4, rowSub + 4, 5, 8);
        ExcelUtil.setCellRangeBorderThin(sheet, cellRangeAddress9_1);
        sheet.addMergedRegion(cellRangeAddress9_1);
        CellRangeAddress cellRangeAddress9_2 = new CellRangeAddress(rowSub + 4, rowSub + 4, 9, 14);
        ExcelUtil.setCellRangeBorderThin(sheet, cellRangeAddress9_2);
        RegionUtil.setBorderRight(BorderStyle.MEDIUM, cellRangeAddress9_2, sheet);
        sheet.addMergedRegion(cellRangeAddress9_2);
        XSSFCellStyle cellStyle9 = workbook.createCellStyle();
        cellStyle9.setAlignment(HorizontalAlignment.RIGHT);
        cellStyle9.setVerticalAlignment(VerticalAlignment.CENTER);
        cellStyle9.setWrapText(true);
        cellStyle9.setBorderBottom(BorderStyle.THIN); //下边框
        cellStyle9.setBorderLeft(BorderStyle.THIN);//左边框
        cellStyle9.setBorderTop(BorderStyle.THIN);//上边框
        cellStyle9.setBorderRight(BorderStyle.THIN);//右边框
        XSSFFont font9 = workbook.createFont();
        font9.setFontName("黑体");
        font9.setFontHeightInPoints((short) 18);
        cellStyle9.setFont(font9);
        Row row9 = ExcelUtil.getRow(sheet, rowSub + 4);
        row9.setHeightInPoints(36);
        Cell cell9_0 = ExcelUtil.getCell(row9, 0);
        cell9_0.setCellStyle(cellStyle9);
        cell9_0.setCellValue("合计：");
        Cell cell9_1 = ExcelUtil.getCell(row9, 5);
        cell9_1.setCellStyle(cellStyle8);
        Cell cell9_2 = ExcelUtil.getCell(row9, 9);
        cell9_2.setCellStyle(cellStyle8);
        if (ObjectUtil.isNull(outerDesignChanges)) {
            cell9_1.setCellValue("0.00");
        } else {
            cell9_1.setCellValue(outerDesignChanges.getDesignChangePrice());
            cell9_2.setCellValue(outerDesignChanges.getDesignChangeRatio() + "%");
        }

        //备注行
        CellRangeAddress cellRangeAddress10 = new CellRangeAddress(rowSub + 5, rowSub + 5, 0, 14);
        RegionUtil.setBorderTop(BorderStyle.MEDIUM, cellRangeAddress10, sheet);
        RegionUtil.setBorderBottom(BorderStyle.THIN, cellRangeAddress10, sheet);
        RegionUtil.setBorderLeft(BorderStyle.MEDIUM, cellRangeAddress10, sheet);
        RegionUtil.setBorderRight(BorderStyle.MEDIUM, cellRangeAddress10, sheet);
        sheet.addMergedRegion(cellRangeAddress10);
        //单元格格式
        XSSFCellStyle cellStyle10 = workbook.createCellStyle();
        cellStyle10.setAlignment(HorizontalAlignment.LEFT);
        cellStyle10.setVerticalAlignment(VerticalAlignment.CENTER);
        cellStyle10.setBorderBottom(BorderStyle.THIN); //下边框
        cellStyle10.setBorderLeft(BorderStyle.MEDIUM);//左边框
        cellStyle10.setBorderTop(BorderStyle.MEDIUM);//上边框
        cellStyle10.setBorderRight(BorderStyle.MEDIUM);//右边框
        XSSFFont font10 = workbook.createFont();
        font10.setFontName("黑体");
        font10.setFontHeightInPoints((short) 16);
        cellStyle10.setFont(font10);
        Row row10 = ExcelUtil.getRow(sheet, rowSub + 5);
        row10.setHeightInPoints(36);
        Cell cell10 = ExcelUtil.getCell(row10, 0);
        cell10.setCellStyle(cellStyle10);
        if (ObjectUtil.isNull(outerDesignChanges)) {
            cell10.setCellValue("备注：");
        } else {
            cell10.setCellValue("备注：" + outerDesignChanges.getParam1());
        }

        //审核行
        CellRangeAddress cellRangeAddress11_0 = new CellRangeAddress(rowSub + 6, rowSub + 8, 0, 2);
        ExcelUtil.setCellRangeBorderThin(sheet, cellRangeAddress11_0);
        RegionUtil.setBorderLeft(BorderStyle.MEDIUM, cellRangeAddress11_0, sheet);
        RegionUtil.setBorderBottom(BorderStyle.MEDIUM, cellRangeAddress11_0, sheet);
        sheet.addMergedRegion(cellRangeAddress11_0);
        CellRangeAddress cellRangeAddress11_1 = new CellRangeAddress(rowSub + 6, rowSub + 6, 3, 11);
        ExcelUtil.setCellRangeBorderThin(sheet, cellRangeAddress11_1);
        sheet.addMergedRegion(cellRangeAddress11_1);
        CellRangeAddress cellRangeAddress11_2 = new CellRangeAddress(rowSub + 6, rowSub + 8, 12, 14);
        ExcelUtil.setCellRangeBorderThin(sheet, cellRangeAddress11_2);
        RegionUtil.setBorderRight(BorderStyle.MEDIUM, cellRangeAddress11_2, sheet);
        RegionUtil.setBorderBottom(BorderStyle.MEDIUM, cellRangeAddress11_2, sheet);
        sheet.addMergedRegion(cellRangeAddress11_2);
        XSSFCellStyle cellStyle11_1 = workbook.createCellStyle();
        cellStyle11_1.setAlignment(HorizontalAlignment.LEFT);
        cellStyle11_1.setVerticalAlignment(VerticalAlignment.CENTER);
        cellStyle11_1.setWrapText(true);
        cellStyle11_1.setBorderBottom(BorderStyle.MEDIUM);
        cellStyle11_1.setBorderLeft(BorderStyle.MEDIUM);
        cellStyle11_1.setBorderTop(BorderStyle.THIN);
        cellStyle11_1.setBorderRight(BorderStyle.THIN);
        XSSFFont font11_1 = workbook.createFont();
        font11_1.setFontName("黑体");
        font11_1.setFontHeightInPoints((short) 20);
        cellStyle11_1.setFont(font11_1);
        XSSFCellStyle cellStyle11_2 = workbook.createCellStyle();
        cellStyle11_2.setAlignment(HorizontalAlignment.CENTER);
        cellStyle11_2.setVerticalAlignment(VerticalAlignment.CENTER);
        cellStyle11_2.setWrapText(true);
        cellStyle11_2.setBorderBottom(BorderStyle.THIN);
        cellStyle11_2.setBorderLeft(BorderStyle.THIN);
        cellStyle11_2.setBorderTop(BorderStyle.THIN);
        cellStyle11_2.setBorderRight(BorderStyle.THIN);
        XSSFFont font11_2 = workbook.createFont();
        font11_2.setFontName("黑体");
        font11_2.setFontHeightInPoints((short) 20);
        cellStyle11_2.setFont(font11_2);
        XSSFCellStyle cellStyle11_3 = workbook.createCellStyle();
        cellStyle11_3.setAlignment(HorizontalAlignment.LEFT);
        cellStyle11_3.setVerticalAlignment(VerticalAlignment.CENTER);
        cellStyle11_3.setWrapText(true);
        cellStyle11_3.setBorderBottom(BorderStyle.MEDIUM);
        cellStyle11_3.setBorderLeft(BorderStyle.THIN);
        cellStyle11_3.setBorderTop(BorderStyle.THIN);
        cellStyle11_3.setBorderRight(BorderStyle.MEDIUM);
        XSSFFont font11_3 = workbook.createFont();
        font11_3.setFontName("黑体");
        font11_3.setFontHeightInPoints((short) 20);
        cellStyle11_3.setFont(font11_3);
        Row row11 = ExcelUtil.getRow(sheet, rowSub + 6);
        row11.setHeightInPoints(36);
        Cell cell11_0 = ExcelUtil.getCell(row11, 0);
        cell11_0.setCellStyle(cellStyle11_1);
        Cell cell11_1 = ExcelUtil.getCell(row11, 3);
        cell11_1.setCellStyle(cellStyle11_2);
        cell11_1.setCellValue("审核");
        Cell cell11_2 = ExcelUtil.getCell(row11, 12);
        cell11_2.setCellStyle(cellStyle11_3);
        if (ObjectUtil.isNull(outerDesignChanges)) {
            cell11_0.setCellValue("拟制：");
            cell11_2.setCellValue("批准：");
        } else {
            String maker = outerDesignChanges.getMaker();
            cell11_0.setCellValue("拟制：" + (StringUtils.isEmpty(maker) ? "" : maker));
            String approver = outerDesignChanges.getApprover();
            cell11_2.setCellValue("批准：" + (StringUtils.isEmpty(approver) ? "" : approver));
        }

        CellRangeAddress cellRangeAddress12_1 = new CellRangeAddress(rowSub + 7, rowSub + 7, 3, 4);
        ExcelUtil.setCellRangeBorderThin(sheet, cellRangeAddress12_1);
        sheet.addMergedRegion(cellRangeAddress12_1);
        CellRangeAddress cellRangeAddress12_3 = new CellRangeAddress(rowSub + 7, rowSub + 7, 6, 8);
        ExcelUtil.setCellRangeBorderThin(sheet, cellRangeAddress12_3);
        sheet.addMergedRegion(cellRangeAddress12_3);
        CellRangeAddress cellRangeAddress12_4 = new CellRangeAddress(rowSub + 7, rowSub + 7, 9, 11);
        ExcelUtil.setCellRangeBorderThin(sheet, cellRangeAddress12_4);
        sheet.addMergedRegion(cellRangeAddress12_4);
        XSSFCellStyle cellStyle12 = workbook.createCellStyle();
        cellStyle12.setAlignment(HorizontalAlignment.CENTER);
        cellStyle12.setVerticalAlignment(VerticalAlignment.CENTER);
        cellStyle12.setWrapText(true);
        cellStyle12.setBorderBottom(BorderStyle.THIN);
        cellStyle12.setBorderLeft(BorderStyle.THIN);
        cellStyle12.setBorderTop(BorderStyle.THIN);
        cellStyle12.setBorderRight(BorderStyle.THIN);
        XSSFFont font12 = workbook.createFont();
        font12.setFontName("黑体");
        font12.setFontHeightInPoints((short) 20);
        cellStyle12.setFont(font12);
        Row row12 = ExcelUtil.getRow(sheet, rowSub + 7);
        row12.setHeightInPoints(36);
        Cell cell12_1 = ExcelUtil.getCell(row12, 3);
        cell12_1.setCellStyle(cellStyle12);
        cell12_1.setCellValue("项目控制室主任");
        Cell cell12_2 = ExcelUtil.getCell(row12, 5);
        cell12_2.setCellStyle(cellStyle12);
        cell12_2.setCellValue("项目经理");
        Cell cell12_3 = ExcelUtil.getCell(row12, 6);
        cell12_3.setCellStyle(cellStyle12);
        cell12_3.setCellValue("项目分部主管领导");
        Cell cell12_4 = ExcelUtil.getCell(row12, 9);
        cell12_4.setCellStyle(cellStyle12);
        cell12_4.setCellValue("技术部部长");

        CellRangeAddress cellRangeAddress13_1 = new CellRangeAddress(rowSub + 8, rowSub + 8, 3, 4);
        ExcelUtil.setCellRangeBorderThin(sheet, cellRangeAddress13_1);
        RegionUtil.setBorderBottom(BorderStyle.MEDIUM, cellRangeAddress13_1, sheet);
        sheet.addMergedRegion(cellRangeAddress13_1);
        CellRangeAddress cellRangeAddress13_3 = new CellRangeAddress(rowSub + 8, rowSub + 8, 6, 8);
        ExcelUtil.setCellRangeBorderThin(sheet, cellRangeAddress13_3);
        RegionUtil.setBorderBottom(BorderStyle.MEDIUM, cellRangeAddress13_3, sheet);
        sheet.addMergedRegion(cellRangeAddress13_3);
        CellRangeAddress cellRangeAddress13_4 = new CellRangeAddress(rowSub + 8, rowSub + 8, 9, 11);
        ExcelUtil.setCellRangeBorderThin(sheet, cellRangeAddress13_4);
        RegionUtil.setBorderBottom(BorderStyle.MEDIUM, cellRangeAddress13_4, sheet);
        sheet.addMergedRegion(cellRangeAddress13_4);
        XSSFCellStyle cellStyle13 = workbook.createCellStyle();
        cellStyle13.setAlignment(HorizontalAlignment.CENTER);
        cellStyle13.setVerticalAlignment(VerticalAlignment.CENTER);
        cellStyle13.setWrapText(true);
        cellStyle13.setBorderBottom(BorderStyle.MEDIUM);
        cellStyle13.setBorderLeft(BorderStyle.THIN);
        cellStyle13.setBorderTop(BorderStyle.THIN);
        cellStyle13.setBorderRight(BorderStyle.THIN);
        XSSFFont font13 = workbook.createFont();
        font13.setFontName("黑体");
        font13.setFontHeightInPoints((short) 20);
        cellStyle13.setFont(font13);
        Row row13 = ExcelUtil.getRow(sheet, rowSub + 8);
        row13.setHeightInPoints(50);
        Cell cell13_1 = ExcelUtil.getCell(row13, 3);
        cell13_1.setCellStyle(cellStyle13);
        Cell cell13_2 = ExcelUtil.getCell(row13, 5);
        cell13_2.setCellStyle(cellStyle13);
        Cell cell13_3 = ExcelUtil.getCell(row13, 6);
        cell13_3.setCellStyle(cellStyle13);
        Cell cell13_4 = ExcelUtil.getCell(row13, 9);
        cell13_4.setCellStyle(cellStyle13);
        if (ObjectUtil.isNotNull(outerDesignChanges)) {
            cell13_1.setCellValue(outerDesignChanges.getControlRoomDirector());
            cell13_2.setCellValue(outerDesignChanges.getManager());
            cell13_3.setCellValue(outerDesignChanges.getLeader());
            cell13_4.setCellValue(outerDesignChanges.getMinister());
        }

        try (FileOutputStream fileOutputStream = new FileOutputStream(filePath)) {
            workbook.write(fileOutputStream);
        } catch (IOException e) {
            e.printStackTrace();
        }
        return resultPath;
    }

    private void exportOutDesignChangeDetailExcel(XSSFWorkbook workbook, XSSFSheet sheet, OuterDesignChangesDetail outerDesignChangesDetail) {
        //列宽
        sheet.setColumnWidth(0, 10 * 256);
        sheet.setColumnWidth(1, 8 * 256);
        sheet.setColumnWidth(2, 8 * 256);
        sheet.setColumnWidth(3, 10 * 256);
        sheet.setColumnWidth(4, 8 * 256);
        sheet.setColumnWidth(5, 8 * 256);
        sheet.setColumnWidth(6, 8 * 256);
        sheet.setColumnWidth(7, 8 * 256);
        sheet.setColumnWidth(8, 10 * 256);
        sheet.setColumnWidth(9, 5 * 256);
        sheet.setColumnWidth(10, 5 * 256);
        sheet.setColumnWidth(11, 8 * 256);

        CellRangeAddress cellRangeAddress0 = new CellRangeAddress(0, 0, 0, 11);
        ExcelUtil.setCellRangeBorderThin(sheet, cellRangeAddress0);
        sheet.addMergedRegion(cellRangeAddress0);
        XSSFCellStyle cellStyle0 = workbook.createCellStyle();
        cellStyle0.setAlignment(HorizontalAlignment.CENTER);
        cellStyle0.setVerticalAlignment(VerticalAlignment.CENTER);
        cellStyle0.setBorderBottom(BorderStyle.THIN);
        cellStyle0.setBorderLeft(BorderStyle.THIN);
        cellStyle0.setBorderTop(BorderStyle.THIN);
        cellStyle0.setBorderRight(BorderStyle.THIN);
        XSSFFont font0 = workbook.createFont();
        font0.setFontName("宋体");
        font0.setFontHeightInPoints((short) 20);
        cellStyle0.setFont(font0);
        Row row0 = ExcelUtil.getRow(sheet, 0);
        row0.setHeightInPoints(36);
        Cell cell0 = ExcelUtil.getCell(row0, 0);
        cell0.setCellStyle(cellStyle0);
        cell0.setCellValue("成都航模模塑股份有限公司模具设变报价单");

        CellRangeAddress cellRangeAddress1_1 = new CellRangeAddress(1, 1, 1, 2);
        ExcelUtil.setCellRangeBorderThin(sheet, cellRangeAddress1_1);
        sheet.addMergedRegion(cellRangeAddress1_1);
        CellRangeAddress cellRangeAddress1_2 = new CellRangeAddress(1, 4, 3, 7);
        ExcelUtil.setCellRangeBorderThin(sheet, cellRangeAddress1_2);
        sheet.addMergedRegion(cellRangeAddress1_2);
        CellRangeAddress cellRangeAddress1_4 = new CellRangeAddress(1, 1, 9, 11);
        ExcelUtil.setCellRangeBorderThin(sheet, cellRangeAddress1_4);
        sheet.addMergedRegion(cellRangeAddress1_4);
        XSSFCellStyle cellStyle1 = workbook.createCellStyle();
        cellStyle1.setAlignment(HorizontalAlignment.CENTER);
        cellStyle1.setVerticalAlignment(VerticalAlignment.CENTER);
        cellStyle1.setWrapText(true);
        cellStyle1.setBorderBottom(BorderStyle.THIN);
        cellStyle1.setBorderLeft(BorderStyle.THIN);
        cellStyle1.setBorderTop(BorderStyle.THIN);
        cellStyle1.setBorderRight(BorderStyle.THIN);
        XSSFFont font1 = workbook.createFont();
        font1.setFontName("宋体");
        font1.setFontHeightInPoints((short) 9);
        cellStyle1.setFont(font1);
        Row row1 = ExcelUtil.getRow(sheet, 1);
        row1.setHeightInPoints(20);
        Cell cell1_0 = ExcelUtil.getCell(row1, 0);
        cell1_0.setCellStyle(cellStyle1);
        cell1_0.setCellValue("项目名称");
        Cell cell1_1 = ExcelUtil.getCell(row1, 1);
        cell1_1.setCellStyle(cellStyle1);
        cell1_1.setCellValue(outerDesignChangesDetail.getProjectName());
        Cell cell1_2 = ExcelUtil.getCell(row1, 3);
        cell1_2.setCellStyle(cellStyle1);
        Cell cell1_3 = ExcelUtil.getCell(row1, 8);
        cell1_3.setCellStyle(cellStyle1);
        cell1_3.setCellValue("模具名称");
        Cell cell1_4 = ExcelUtil.getCell(row1, 9);
        cell1_4.setCellStyle(cellStyle1);
        cell1_4.setCellValue(outerDesignChangesDetail.getMoldName());

        CellRangeAddress cellRangeAddress2_1 = new CellRangeAddress(2, 2, 1, 2);
        ExcelUtil.setCellRangeBorderThin(sheet, cellRangeAddress2_1);
        sheet.addMergedRegion(cellRangeAddress2_1);
        CellRangeAddress cellRangeAddress2_4 = new CellRangeAddress(2, 2, 9, 11);
        ExcelUtil.setCellRangeBorderThin(sheet, cellRangeAddress2_4);
        sheet.addMergedRegion(cellRangeAddress2_4);
        Row row2 = ExcelUtil.getRow(sheet, 2);
        row2.setHeightInPoints(20);
        Cell cell2_0 = ExcelUtil.getCell(row2, 0);
        cell2_0.setCellStyle(cellStyle1);
        cell2_0.setCellValue("产品名称");
        Cell cell2_1 = ExcelUtil.getCell(row2, 1);
        cell2_1.setCellStyle(cellStyle1);
        cell2_1.setCellValue(outerDesignChangesDetail.getProductName());
        Cell cell2_3 = ExcelUtil.getCell(row2, 8);
        cell2_3.setCellStyle(cellStyle1);
        cell2_3.setCellValue("模具编号");
        Cell cell2_4 = ExcelUtil.getCell(row2, 9);
        cell2_4.setCellStyle(cellStyle1);
        cell2_4.setCellValue(outerDesignChangesDetail.getMoldId());

        CellRangeAddress cellRangeAddress3_1 = new CellRangeAddress(3, 3, 1, 2);
        ExcelUtil.setCellRangeBorderThin(sheet, cellRangeAddress3_1);
        sheet.addMergedRegion(cellRangeAddress3_1);
        Row row3 = ExcelUtil.getRow(sheet, 3);
        row3.setHeightInPoints(20);
        Cell cell3_0 = ExcelUtil.getCell(row3, 0);
        cell3_0.setCellStyle(cellStyle1);
        cell3_0.setCellValue("设变单号");
        Cell cell3_1 = ExcelUtil.getCell(row3, 1);
        cell3_1.setCellStyle(cellStyle1);
        cell3_1.setCellValue(outerDesignChangesDetail.getDesignChangesCode());
        Cell cell3_3 = ExcelUtil.getCell(row3, 8);
        cell3_3.setCellStyle(cellStyle1);
        cell3_3.setCellValue("模具外形");
        Cell cell3_4 = ExcelUtil.getCell(row3, 9);
        cell3_4.setCellStyle(cellStyle1);
        cell3_4.setCellValue(outerDesignChangesDetail.getMoldLength());
        Cell cell3_5 = ExcelUtil.getCell(row3, 10);
        cell3_5.setCellStyle(cellStyle1);
        cell3_5.setCellValue(outerDesignChangesDetail.getMoldWidth());
        Cell cell3_6 = ExcelUtil.getCell(row3, 11);
        cell3_6.setCellStyle(cellStyle1);
        cell3_6.setCellValue(outerDesignChangesDetail.getMoldHeight());

        CellRangeAddress cellRangeAddress4_1 = new CellRangeAddress(4, 4, 1, 2);
        ExcelUtil.setCellRangeBorderThin(sheet, cellRangeAddress4_1);
        sheet.addMergedRegion(cellRangeAddress4_1);
        CellRangeAddress cellRangeAddress4_4 = new CellRangeAddress(4, 4, 9, 11);
        ExcelUtil.setCellRangeBorderThin(sheet, cellRangeAddress4_4);
        sheet.addMergedRegion(cellRangeAddress4_4);
        Row row4 = ExcelUtil.getRow(sheet, 4);
        row4.setHeightInPoints(20);
        Cell cell4_0 = ExcelUtil.getCell(row4, 0);
        cell4_0.setCellStyle(cellStyle1);
        cell4_0.setCellValue("设变周期");
        Cell cell4_1 = ExcelUtil.getCell(row4, 1);
        cell4_1.setCellStyle(cellStyle1);
        cell4_1.setCellValue(outerDesignChangesDetail.getChangedPeriod());
        Cell cell4_3 = ExcelUtil.getCell(row4, 8);
        cell4_3.setCellStyle(cellStyle1);
        cell4_3.setCellValue("定义机台");
        Cell cell4_4 = ExcelUtil.getCell(row4, 9);
        cell4_4.setCellStyle(cellStyle1);
        cell4_4.setCellValue(outerDesignChangesDetail.getPress());

        CellRangeAddress cellRangeAddress5_1 = new CellRangeAddress(5, 5, 1, 11);
        ExcelUtil.setCellRangeBorderThin(sheet, cellRangeAddress5_1);
        sheet.addMergedRegion(cellRangeAddress5_1);
        Row row5 = ExcelUtil.getRow(sheet, 5);
        row5.setHeightInPoints(60);
        Cell cell5_0 = ExcelUtil.getCell(row5, 0);
        cell5_0.setCellStyle(cellStyle1);
        cell5_0.setCellValue("设变内容");
        Cell cell5_1 = ExcelUtil.getCell(row5, 1);
        cell5_1.setCellStyle(cellStyle1);
        cell5_1.setCellValue(outerDesignChangesDetail.getContent());

        CellRangeAddress cellRangeAddress6_1 = new CellRangeAddress(6, 6, 1, 11);
        ExcelUtil.setCellRangeBorderThin(sheet, cellRangeAddress6_1);
        sheet.addMergedRegion(cellRangeAddress6_1);
        Row row6 = ExcelUtil.getRow(sheet, 6);
        row6.setHeightInPoints(60);
        Cell cell6_0 = ExcelUtil.getCell(row6, 0);
        cell6_0.setCellStyle(cellStyle1);
        cell6_0.setCellValue("整改方案");
        Cell cell6_1 = ExcelUtil.getCell(row6, 1);
        cell6_1.setCellStyle(cellStyle1);
        cell6_1.setCellValue(outerDesignChangesDetail.getRectificationPlan());

        CellRangeAddress cellRangeAddress7_0 = new CellRangeAddress(7, 7, 0, 10);
        ExcelUtil.setCellRangeBorderThin(sheet, cellRangeAddress7_0);
        sheet.addMergedRegion(cellRangeAddress7_0);
        CellRangeAddress cellRangeAddress7_1 = new CellRangeAddress(7, 8, 11, 11);
        ExcelUtil.setCellRangeBorderThin(sheet, cellRangeAddress7_1);
        sheet.addMergedRegion(cellRangeAddress7_1);
        Row row7 = ExcelUtil.getRow(sheet, 7);
        row7.setHeightInPoints(20);
        Cell cell7_0 = ExcelUtil.getCell(row7, 0);
        cell7_0.setCellStyle(cellStyle1);
        cell7_0.setCellValue("报价明细");
        Cell cell7_1 = ExcelUtil.getCell(row7, 11);
        cell7_1.setCellStyle(cellStyle1);
        cell7_1.setCellValue("核价明细");

        CellRangeAddress cellRangeAddress8_1 = new CellRangeAddress(8, 8, 1, 2);
        ExcelUtil.setCellRangeBorderThin(sheet, cellRangeAddress8_1);
        sheet.addMergedRegion(cellRangeAddress8_1);
        CellRangeAddress cellRangeAddress8_3 = new CellRangeAddress(8, 8, 4, 7);
        ExcelUtil.setCellRangeBorderThin(sheet, cellRangeAddress8_3);
        sheet.addMergedRegion(cellRangeAddress8_3);
        CellRangeAddress cellRangeAddress8_5 = new CellRangeAddress(8, 8, 9, 10);
        ExcelUtil.setCellRangeBorderThin(sheet, cellRangeAddress8_5);
        sheet.addMergedRegion(cellRangeAddress8_5);
        Row row8 = ExcelUtil.getRow(sheet, 8);
        row8.setHeightInPoints(20);
        Cell cell8_0 = ExcelUtil.getCell(row8, 0);
        cell8_0.setCellStyle(cellStyle1);
        cell8_0.setCellValue("科目");
        Cell cell8_1 = ExcelUtil.getCell(row8, 1);
        cell8_1.setCellStyle(cellStyle1);
        cell8_1.setCellValue("项目");
        Cell cell8_2 = ExcelUtil.getCell(row8, 3);
        cell8_2.setCellStyle(cellStyle1);
        cell8_2.setCellValue("单价（元）");
        Cell cell8_3 = ExcelUtil.getCell(row8, 4);
        cell8_3.setCellStyle(cellStyle1);
        cell8_3.setCellValue("工时h/里程km");
        Cell cell8_4 = ExcelUtil.getCell(row8, 8);
        cell8_4.setCellStyle(cellStyle1);
        cell8_4.setCellValue("金额（元）");
        Cell cell8_5 = ExcelUtil.getCell(row8, 9);
        cell8_5.setCellStyle(cellStyle1);

        int rowNum = 9;
        List<OuterDesignChangePrice> outerDesignChangePrices = outerDesignChangePriceMapper.selectList(new LambdaQueryWrapper<OuterDesignChangePrice>()
                .eq(OuterDesignChangePrice::getMoldSelectionId, outerDesignChangesDetail.getMoldSelectionId())
                .eq(OuterDesignChangePrice::getDesignChangeId, outerDesignChangesDetail.getId()));
        Map<String, List<OuterDesignChangePrice>> typeMap = outerDesignChangePrices.stream().collect(Collectors.groupingBy(OuterDesignChangePrice::getType));
        rowNum = exportOutDesignChangePriceExcel(sheet, cellStyle1, rowNum, typeMap, "设计费用", outerDesignChangesDetail.getDesignFeeTotal());
        rowNum = exportOutDesignChangePriceExcel(sheet, cellStyle1, rowNum, typeMap, "加工费用", outerDesignChangesDetail.getMachiningFeeTotal());
        rowNum = exportOutDesignChangePriceExcel(sheet, cellStyle1, rowNum, typeMap, "检测费用", outerDesignChangesDetail.getTestFeeTotal());
        rowNum = exportOutDesignChangePriceExcel(sheet, cellStyle1, rowNum, typeMap, "试模费用", outerDesignChangesDetail.getTryoutFeeTotal());
        rowNum = exportOutDesignChangePriceExcel(sheet, cellStyle1, rowNum, typeMap, "运输费用", outerDesignChangesDetail.getTransportFeeTotal());
        rowNum = exportOutDesignChangePriceExcel2(sheet, cellStyle1, rowNum, typeMap, "材料费用", outerDesignChangesDetail);
        rowNum = exportOutDesignChangePriceExcel3(sheet, cellStyle1, rowNum, typeMap, "其它费用", outerDesignChangesDetail);

        CellRangeAddress cellRangeAddress99_2 = new CellRangeAddress(rowNum, rowNum, 2, 3);
        ExcelUtil.setCellRangeBorderThin(sheet, cellRangeAddress99_2);
        sheet.addMergedRegion(cellRangeAddress99_2);
        CellRangeAddress cellRangeAddress99_4 = new CellRangeAddress(rowNum, rowNum, 5, 6);
        ExcelUtil.setCellRangeBorderThin(sheet, cellRangeAddress99_4);
        sheet.addMergedRegion(cellRangeAddress99_4);
        CellRangeAddress cellRangeAddress99_7 = new CellRangeAddress(rowNum, rowNum, 9, 10);
        ExcelUtil.setCellRangeBorderThin(sheet, cellRangeAddress99_7);
        sheet.addMergedRegion(cellRangeAddress99_7);
        Row row99 = ExcelUtil.getRow(sheet, rowNum);
        row99.setHeightInPoints(36);
        Cell cell99_0 = ExcelUtil.getCell(row99, 0);
        cell99_0.setCellStyle(cellStyle1);
        cell99_0.setCellValue("供应商：");
        Cell cell99_1 = ExcelUtil.getCell(row99, 1);
        cell99_1.setCellStyle(cellStyle1);
        final String supplier = outerDesignChangesDetail.getSupplier();
        if (StringUtils.isNotEmpty(supplier)) {
            final DictTable dictTable = dictTableMapper.selectOne(new LambdaQueryWrapper<DictTable>().eq(DictTable::getDicId, supplier));
            if (ObjectUtil.isNotEmpty(dictTable)) {
                cell99_1.setCellValue(dictTable.getDicName());
            }
        }
        Cell cell99_2 = ExcelUtil.getCell(row99, 2);
        cell99_2.setCellStyle(cellStyle1);
        cell99_2.setCellValue("供应商报价人签字：");
        Cell cell99_3 = ExcelUtil.getCell(row99, 4);
        cell99_3.setCellStyle(cellStyle1);
        cell99_3.setCellValue(outerDesignChangesDetail.getBidder());
        Cell cell99_4 = ExcelUtil.getCell(row99, 5);
        cell99_4.setCellStyle(cellStyle1);
        cell99_4.setCellValue("时间：");
        Cell cell99_5 = ExcelUtil.getCell(row99, 7);
        cell99_5.setCellStyle(cellStyle1);
        cell99_5.setCellValue(outerDesignChangesDetail.getTime());
        Cell cell99_6 = ExcelUtil.getCell(row99, 8);
        cell99_6.setCellStyle(cellStyle1);
        cell99_6.setCellValue("合计：");
        Cell cell99_7 = ExcelUtil.getCell(row99, 9);
        cell99_7.setCellStyle(cellStyle1);
        cell99_7.setCellValue(outerDesignChangesDetail.getTotalFee());
        Cell cell99_8 = ExcelUtil.getCell(row99, 11);
        cell99_8.setCellStyle(cellStyle1);
        cell99_8.setCellValue(outerDesignChangesDetail.getTotalFeeCheck());
        rowNum++;

        XSSFCellStyle cellStyle100 = workbook.createCellStyle();
        cellStyle100.setAlignment(HorizontalAlignment.LEFT);
        cellStyle100.setVerticalAlignment(VerticalAlignment.CENTER);
        cellStyle100.setWrapText(true);
        cellStyle100.setBorderBottom(BorderStyle.THIN);
        cellStyle100.setBorderLeft(BorderStyle.THIN);
        cellStyle100.setBorderTop(BorderStyle.THIN);
        cellStyle100.setBorderRight(BorderStyle.THIN);
        XSSFFont font100 = workbook.createFont();
        font100.setBold(true);
        font100.setFontName("宋体");
        font100.setFontHeightInPoints((short) 9);
        cellStyle100.setFont(font100);
        CellRangeAddress cellRangeAddress100_0 = new CellRangeAddress(rowNum, rowNum, 0, 2);
        ExcelUtil.setCellRangeBorderThin(sheet, cellRangeAddress100_0);
        sheet.addMergedRegion(cellRangeAddress100_0);
        CellRangeAddress cellRangeAddress100_1 = new CellRangeAddress(rowNum, rowNum, 3, 6);
        ExcelUtil.setCellRangeBorderThin(sheet, cellRangeAddress100_1);
        sheet.addMergedRegion(cellRangeAddress100_1);
        CellRangeAddress cellRangeAddress100_2 = new CellRangeAddress(rowNum, rowNum, 7, 11);
        ExcelUtil.setCellRangeBorderThin(sheet, cellRangeAddress100_2);
        sheet.addMergedRegion(cellRangeAddress100_2);
        Row row100 = ExcelUtil.getRow(sheet, rowNum);
        row100.setHeightInPoints(36);
        Cell cell100_0 = ExcelUtil.getCell(row100, 0);
        cell100_0.setCellStyle(cellStyle100);
        String maker = outerDesignChangesDetail.getMaker();
        cell100_0.setCellValue("拟制：" + (StringUtils.isEmpty(maker) ? "" : maker));
        Cell cell100_1 = ExcelUtil.getCell(row100, 3);
        cell100_1.setCellStyle(cellStyle100);
        String auditor = outerDesignChangesDetail.getAuditor();
        cell100_1.setCellValue("审核：" + (StringUtils.isEmpty(auditor) ? "" : auditor));
        Cell cell100_2 = ExcelUtil.getCell(row100, 7);
        cell100_2.setCellStyle(cellStyle100);
        String approver = outerDesignChangesDetail.getApprover();
        cell100_2.setCellValue("批准：" + (StringUtils.isEmpty(approver) ? "" : approver));
    }

    private int exportOutDesignChangePriceExcel(XSSFSheet sheet, XSSFCellStyle xssfCellStyle, int rowNum, Map<String, List<OuterDesignChangePrice>> typeMap, String type, String designFeeTotal) {
        if (typeMap.containsKey(type)) {
            List<OuterDesignChangePrice> outerDesignChangePricesList = typeMap.get(type);
            int size = outerDesignChangePricesList.size();
            if (size > 1) {
                CellRangeAddress typeCellRangeAddress = new CellRangeAddress(rowNum, rowNum + size - 1, 0, 0);
                ExcelUtil.setCellRangeBorderThin(sheet, typeCellRangeAddress);
                sheet.addMergedRegion(typeCellRangeAddress);
                CellRangeAddress subtotalCellRangeAddress = new CellRangeAddress(rowNum, rowNum + size - 1, 9, 10);
                ExcelUtil.setCellRangeBorderThin(sheet, subtotalCellRangeAddress);
                sheet.addMergedRegion(subtotalCellRangeAddress);
                Row firstRow = ExcelUtil.getRow(sheet, rowNum);
                Cell cell_0 = ExcelUtil.getCell(firstRow, 0);
                cell_0.setCellStyle(xssfCellStyle);
                cell_0.setCellValue(type);
                Cell cell_5 = ExcelUtil.getCell(firstRow, 9);
                cell_5.setCellStyle(xssfCellStyle);
                cell_5.setCellValue(designFeeTotal);
                for (int i = 0; i < size; i++) {
                    CellRangeAddress cellRangeAddress_1 = new CellRangeAddress(rowNum, rowNum, 1, 2);
                    ExcelUtil.setCellRangeBorderThin(sheet, cellRangeAddress_1);
                    sheet.addMergedRegion(cellRangeAddress_1);
                    CellRangeAddress cellRangeAddress_3 = new CellRangeAddress(rowNum, rowNum, 4, 7);
                    ExcelUtil.setCellRangeBorderThin(sheet, cellRangeAddress_3);
                    sheet.addMergedRegion(cellRangeAddress_3);
                    Row row = ExcelUtil.getRow(sheet, rowNum);
                    row.setHeightInPoints(20);
                    OuterDesignChangePrice outerDesignChangePrice = outerDesignChangePricesList.get(i);
                    Cell cell_1 = ExcelUtil.getCell(row, 1);
                    cell_1.setCellStyle(xssfCellStyle);
                    cell_1.setCellValue(outerDesignChangePrice.getName());
                    Cell cell_2 = ExcelUtil.getCell(row, 3);
                    cell_2.setCellStyle(xssfCellStyle);
                    cell_2.setCellValue(outerDesignChangePrice.getPrice());
                    Cell cell_3 = ExcelUtil.getCell(row, 4);
                    cell_3.setCellStyle(xssfCellStyle);
                    cell_3.setCellValue(outerDesignChangePrice.getNum());
                    Cell cell_4 = ExcelUtil.getCell(row, 8);
                    cell_4.setCellStyle(xssfCellStyle);
                    cell_4.setCellValue(outerDesignChangePrice.getTotalPrice());
                    Cell cell_6 = ExcelUtil.getCell(row, 11);
                    cell_6.setCellStyle(xssfCellStyle);
                    cell_6.setCellValue(outerDesignChangePrice.getCheckPrice());
                    rowNum++;
                }
            } else {
                CellRangeAddress cellRangeAddress_1 = new CellRangeAddress(rowNum, rowNum, 1, 2);
                ExcelUtil.setCellRangeBorderThin(sheet, cellRangeAddress_1);
                sheet.addMergedRegion(cellRangeAddress_1);
                CellRangeAddress cellRangeAddress_3 = new CellRangeAddress(rowNum, rowNum, 4, 7);
                ExcelUtil.setCellRangeBorderThin(sheet, cellRangeAddress_3);
                sheet.addMergedRegion(cellRangeAddress_3);
                CellRangeAddress cellRangeAddress_5 = new CellRangeAddress(rowNum, rowNum, 9, 10);
                ExcelUtil.setCellRangeBorderThin(sheet, cellRangeAddress_5);
                sheet.addMergedRegion(cellRangeAddress_5);
                Row row = ExcelUtil.getRow(sheet, rowNum);
                row.setHeightInPoints(20);
                OuterDesignChangePrice outerDesignChangePrice = outerDesignChangePricesList.get(0);
                Cell cell_0 = ExcelUtil.getCell(row, 0);
                cell_0.setCellStyle(xssfCellStyle);
                cell_0.setCellValue(type);
                Cell cell_1 = ExcelUtil.getCell(row, 1);
                cell_1.setCellStyle(xssfCellStyle);
                cell_1.setCellValue(outerDesignChangePrice.getName());
                Cell cell_2 = ExcelUtil.getCell(row, 3);
                cell_2.setCellStyle(xssfCellStyle);
                cell_2.setCellValue(outerDesignChangePrice.getPrice());
                Cell cell_3 = ExcelUtil.getCell(row, 4);
                cell_3.setCellStyle(xssfCellStyle);
                cell_3.setCellValue(outerDesignChangePrice.getNum());
                Cell cell_4 = ExcelUtil.getCell(row, 8);
                cell_4.setCellStyle(xssfCellStyle);
                cell_4.setCellValue(outerDesignChangePrice.getTotalPrice());
                Cell cell_5 = ExcelUtil.getCell(row, 9);
                cell_5.setCellStyle(xssfCellStyle);
                cell_5.setCellValue(designFeeTotal);
                Cell cell_6 = ExcelUtil.getCell(row, 11);
                cell_6.setCellStyle(xssfCellStyle);
                cell_6.setCellValue(outerDesignChangePrice.getCheckPrice());
                rowNum++;
            }
        }
        return rowNum;
    }

    private int exportOutDesignChangePriceExcel2(XSSFSheet sheet, XSSFCellStyle xssfCellStyle, int rowNum, Map<String, List<OuterDesignChangePrice>> typeMap, String type, OuterDesignChangesDetail outerDesignChangesDetail) {
        if (typeMap.containsKey(type)) {
            List<OuterDesignChangePrice> outerDesignChangePricesList = typeMap.get(type);
            int size = outerDesignChangePricesList.size();
            CellRangeAddress typeCellRangeAddress = new CellRangeAddress(rowNum, rowNum + size, 0, 0);
            ExcelUtil.setCellRangeBorderThin(sheet, typeCellRangeAddress);
            sheet.addMergedRegion(typeCellRangeAddress);
            CellRangeAddress sizeCellRangeAddress = new CellRangeAddress(rowNum, rowNum, 4, 6);
            ExcelUtil.setCellRangeBorderThin(sheet, sizeCellRangeAddress);
            sheet.addMergedRegion(sizeCellRangeAddress);
            CellRangeAddress subtotalCellRangeAddress0 = new CellRangeAddress(rowNum, rowNum, 9, 10);
            ExcelUtil.setCellRangeBorderThin(sheet, subtotalCellRangeAddress0);
            sheet.addMergedRegion(subtotalCellRangeAddress0);
            Row firstRow = ExcelUtil.getRow(sheet, rowNum);
            Cell cell_0_0 = ExcelUtil.getCell(firstRow, 0);
            cell_0_0.setCellStyle(xssfCellStyle);
            cell_0_0.setCellValue(type);
            Cell cell_0_1 = ExcelUtil.getCell(firstRow, 1);
            cell_0_1.setCellStyle(xssfCellStyle);
            cell_0_1.setCellValue("名称");
            Cell cell_0_2 = ExcelUtil.getCell(firstRow, 2);
            cell_0_2.setCellStyle(xssfCellStyle);
            cell_0_2.setCellValue("牌号");
            Cell cell_0_3 = ExcelUtil.getCell(firstRow, 3);
            cell_0_3.setCellStyle(xssfCellStyle);
            cell_0_3.setCellValue("单价（元）");
            Cell cell_0_4 = ExcelUtil.getCell(firstRow, 4);
            cell_0_4.setCellStyle(xssfCellStyle);
            cell_0_4.setCellValue("规格mm");
            Cell cell_0_5 = ExcelUtil.getCell(firstRow, 7);
            cell_0_5.setCellStyle(xssfCellStyle);
            cell_0_5.setCellValue("重量kg/数量");
            Cell cell_0_6 = ExcelUtil.getCell(firstRow, 8);
            cell_0_6.setCellStyle(xssfCellStyle);
            cell_0_6.setCellValue("金额（元）");
            Cell cell_0_7 = ExcelUtil.getCell(firstRow, 9);
            cell_0_7.setCellStyle(xssfCellStyle);
            Cell cell_0_8 = ExcelUtil.getCell(firstRow, 11);
            cell_0_8.setCellStyle(xssfCellStyle);
            cell_0_8.setCellValue(outerDesignChangesDetail.getMainFeeCheck());
            String designFeeTotal = outerDesignChangesDetail.getMaterialFeeTotal();
            rowNum++;
            if (size > 1) {
                CellRangeAddress subtotalCellRangeAddress = new CellRangeAddress(rowNum, rowNum + size - 1, 9, 10);
                ExcelUtil.setCellRangeBorderThin(sheet, subtotalCellRangeAddress);
                sheet.addMergedRegion(subtotalCellRangeAddress);
                Row secondRow = ExcelUtil.getRow(sheet, rowNum);
                Cell cell_1_9 = ExcelUtil.getCell(secondRow, 9);
                cell_1_9.setCellStyle(xssfCellStyle);
                cell_1_9.setCellValue(designFeeTotal);
                for (int i = 0; i < size; i++) {
                    Row row = ExcelUtil.getRow(sheet, rowNum);
                    row.setHeightInPoints(20);
                    OuterDesignChangePrice outerDesignChangePrice = outerDesignChangePricesList.get(i);
                    Cell cell_1 = ExcelUtil.getCell(row, 1);
                    cell_1.setCellStyle(xssfCellStyle);
                    cell_1.setCellValue(outerDesignChangePrice.getName());
                    Cell cell_2 = ExcelUtil.getCell(row, 2);
                    cell_2.setCellStyle(xssfCellStyle);
                    cell_2.setCellValue(outerDesignChangePrice.getSpecification());
                    Cell cell_3 = ExcelUtil.getCell(row, 3);
                    cell_3.setCellStyle(xssfCellStyle);
                    cell_3.setCellValue(outerDesignChangePrice.getPrice());
                    Cell cell_4 = ExcelUtil.getCell(row, 4);
                    cell_4.setCellStyle(xssfCellStyle);
                    cell_4.setCellValue(outerDesignChangePrice.getLength());
                    Cell cell_5 = ExcelUtil.getCell(row, 5);
                    cell_5.setCellStyle(xssfCellStyle);
                    cell_5.setCellValue(outerDesignChangePrice.getWidth());
                    Cell cell_6 = ExcelUtil.getCell(row, 6);
                    cell_6.setCellStyle(xssfCellStyle);
                    cell_6.setCellValue(outerDesignChangePrice.getHeight());
                    Cell cell_7 = ExcelUtil.getCell(row, 7);
                    cell_7.setCellStyle(xssfCellStyle);
                    cell_7.setCellValue(outerDesignChangePrice.getNum());
                    Cell cell_8 = ExcelUtil.getCell(row, 8);
                    cell_8.setCellStyle(xssfCellStyle);
                    cell_8.setCellValue(outerDesignChangePrice.getTotalPrice());
                    Cell cell_10 = ExcelUtil.getCell(row, 11);
                    cell_10.setCellStyle(xssfCellStyle);
                    cell_10.setCellValue(outerDesignChangePrice.getCheckPrice());
                    rowNum++;
                }
            } else {
                Row row = ExcelUtil.getRow(sheet, rowNum);
                row.setHeightInPoints(20);
                OuterDesignChangePrice outerDesignChangePrice = outerDesignChangePricesList.get(0);
                Cell cell_1 = ExcelUtil.getCell(row, 1);
                cell_1.setCellStyle(xssfCellStyle);
                cell_1.setCellValue(outerDesignChangePrice.getName());
                Cell cell_2 = ExcelUtil.getCell(row, 2);
                cell_2.setCellStyle(xssfCellStyle);
                cell_2.setCellValue(outerDesignChangePrice.getSpecification());
                Cell cell_3 = ExcelUtil.getCell(row, 3);
                cell_3.setCellStyle(xssfCellStyle);
                cell_3.setCellValue(outerDesignChangePrice.getPrice());
                Cell cell_4 = ExcelUtil.getCell(row, 4);
                cell_4.setCellStyle(xssfCellStyle);
                cell_4.setCellValue(outerDesignChangePrice.getLength());
                Cell cell_5 = ExcelUtil.getCell(row, 5);
                cell_5.setCellStyle(xssfCellStyle);
                cell_5.setCellValue(outerDesignChangePrice.getWidth());
                Cell cell_6 = ExcelUtil.getCell(row, 6);
                cell_6.setCellStyle(xssfCellStyle);
                cell_6.setCellValue(outerDesignChangePrice.getHeight());
                Cell cell_7 = ExcelUtil.getCell(row, 7);
                cell_7.setCellStyle(xssfCellStyle);
                cell_7.setCellValue(outerDesignChangePrice.getNum());
                Cell cell_8 = ExcelUtil.getCell(row, 8);
                cell_8.setCellStyle(xssfCellStyle);
                cell_8.setCellValue(outerDesignChangePrice.getTotalPrice());
                Cell cell_10 = ExcelUtil.getCell(row, 11);
                cell_10.setCellStyle(xssfCellStyle);
                cell_10.setCellValue(outerDesignChangePrice.getCheckPrice());
                rowNum++;
            }
        }
        return rowNum;
    }

    private int exportOutDesignChangePriceExcel3(XSSFSheet sheet, XSSFCellStyle xssfCellStyle, int rowNum, Map<String, List<OuterDesignChangePrice>> typeMap, String type, OuterDesignChangesDetail outerDesignChangesDetail) {
        if (typeMap.containsKey(type)) {
            List<OuterDesignChangePrice> outerDesignChangePricesList = typeMap.get(type);
            int size = outerDesignChangePricesList.size();
            CellRangeAddress typeCellRangeAddress = new CellRangeAddress(rowNum, rowNum + size, 0, 0);
            ExcelUtil.setCellRangeBorderThin(sheet, typeCellRangeAddress);
            sheet.addMergedRegion(typeCellRangeAddress);
            CellRangeAddress sizeCellRangeAddress = new CellRangeAddress(rowNum, rowNum, 3, 8);
            ExcelUtil.setCellRangeBorderThin(sheet, sizeCellRangeAddress);
            sheet.addMergedRegion(sizeCellRangeAddress);
            CellRangeAddress subtotalCellRangeAddress0 = new CellRangeAddress(rowNum, rowNum, 9, 10);
            ExcelUtil.setCellRangeBorderThin(sheet, subtotalCellRangeAddress0);
            sheet.addMergedRegion(subtotalCellRangeAddress0);
            Row firstRow = ExcelUtil.getRow(sheet, rowNum);
            firstRow.setHeightInPoints(20);
            Cell cell_0_0 = ExcelUtil.getCell(firstRow, 0);
            cell_0_0.setCellStyle(xssfCellStyle);
            cell_0_0.setCellValue(type);
            Cell cell_0_1 = ExcelUtil.getCell(firstRow, 1);
            cell_0_1.setCellStyle(xssfCellStyle);
            cell_0_1.setCellValue("科目");
            Cell cell_0_2 = ExcelUtil.getCell(firstRow, 2);
            cell_0_2.setCellStyle(xssfCellStyle);
            cell_0_2.setCellValue("比例");
            Cell cell_0_3 = ExcelUtil.getCell(firstRow, 3);
            cell_0_3.setCellStyle(xssfCellStyle);
            cell_0_3.setCellValue("金额（元）");
            Cell cell_0_7 = ExcelUtil.getCell(firstRow, 9);
            cell_0_7.setCellStyle(xssfCellStyle);
            Cell cell_0_8 = ExcelUtil.getCell(firstRow, 11);
            cell_0_8.setCellStyle(xssfCellStyle);
            cell_0_8.setCellValue(outerDesignChangesDetail.getMaterialFeeCheck());
            String designFeeTotal = outerDesignChangesDetail.getOtherFeeTotal();
            rowNum++;
            if (size > 1) {
                CellRangeAddress subtotalCellRangeAddress = new CellRangeAddress(rowNum, rowNum + size - 1, 9, 10);
                ExcelUtil.setCellRangeBorderThin(sheet, subtotalCellRangeAddress);
                sheet.addMergedRegion(subtotalCellRangeAddress);
                Row secondRow = ExcelUtil.getRow(sheet, rowNum);
                Cell cell_1_9 = ExcelUtil.getCell(secondRow, 9);
                cell_1_9.setCellStyle(xssfCellStyle);
                cell_1_9.setCellValue(designFeeTotal);
                for (int i = 0; i < size; i++) {
                    CellRangeAddress totalPriceCellRangeAddress = new CellRangeAddress(rowNum, rowNum, 3, 8);
                    ExcelUtil.setCellRangeBorderThin(sheet, totalPriceCellRangeAddress);
                    sheet.addMergedRegion(totalPriceCellRangeAddress);
                    Row row = ExcelUtil.getRow(sheet, rowNum);
                    row.setHeightInPoints(20);
                    OuterDesignChangePrice outerDesignChangePrice = outerDesignChangePricesList.get(i);
                    Cell cell_1 = ExcelUtil.getCell(row, 1);
                    cell_1.setCellStyle(xssfCellStyle);
                    cell_1.setCellValue(outerDesignChangePrice.getName());
                    Cell cell_2 = ExcelUtil.getCell(row, 2);
                    cell_2.setCellStyle(xssfCellStyle);
                    cell_2.setCellValue(outerDesignChangePrice.getNum());
                    Cell cell_3 = ExcelUtil.getCell(row, 3);
                    cell_3.setCellStyle(xssfCellStyle);
                    cell_3.setCellValue(outerDesignChangePrice.getTotalPrice());
                    Cell cell_10 = ExcelUtil.getCell(row, 11);
                    cell_10.setCellStyle(xssfCellStyle);
                    cell_10.setCellValue(outerDesignChangePrice.getCheckPrice());
                    rowNum++;
                }
            } else {
                CellRangeAddress totalPriceCellRangeAddress = new CellRangeAddress(rowNum, rowNum, 3, 8);
                ExcelUtil.setCellRangeBorderThin(sheet, totalPriceCellRangeAddress);
                sheet.addMergedRegion(totalPriceCellRangeAddress);
                Row row = ExcelUtil.getRow(sheet, rowNum);
                row.setHeightInPoints(20);
                OuterDesignChangePrice outerDesignChangePrice = outerDesignChangePricesList.get(0);
                Cell cell_1 = ExcelUtil.getCell(row, 1);
                cell_1.setCellStyle(xssfCellStyle);
                cell_1.setCellValue(outerDesignChangePrice.getName());
                Cell cell_2 = ExcelUtil.getCell(row, 2);
                cell_2.setCellStyle(xssfCellStyle);
                cell_2.setCellValue(outerDesignChangePrice.getNum());
                Cell cell_3 = ExcelUtil.getCell(row, 3);
                cell_3.setCellStyle(xssfCellStyle);
                cell_3.setCellValue(outerDesignChangePrice.getTotalPrice());
                Cell cell_10 = ExcelUtil.getCell(row, 11);
                cell_10.setCellStyle(xssfCellStyle);
                cell_10.setCellValue(outerDesignChangePrice.getCheckPrice());
                rowNum++;
            }
        }
        return rowNum;
    }

    @Override
    public String saveOutDesignChange(JSONObject jsonObject, HttpServletRequest request) {
        OuterDesignChanges outerDesignChanges = new OuterDesignChanges();
        //jsonobject解析获取列表数据
        JSONArray dataList = jsonObject.getJSONArray("dataList");
        //jsonobject解析获取供应商含税总价
        String totalFee = jsonObject.getString("totalFee");
        outerDesignChanges.setSupplierFeeTotal(BigdecimalUtil.stringTo2DecimalString(totalFee));
        //jsonobject解析获取设变目标价占总模具费用比例总价
        String chanedRatio = jsonObject.getString("chanedRatio");
        outerDesignChanges.setDesignChangeRatio(BigdecimalUtil.stringTo2DecimalString(chanedRatio));
        //jsonobject解析获取设变目标价费用总价
        String chanedFee = jsonObject.getString("chanedFee");
        outerDesignChanges.setDesignChangePrice(BigdecimalUtil.stringTo2DecimalString(chanedFee));
        //jsonobject解析获取项目模具总费用
        String moldFeeIncludedTax = jsonObject.getString("moldFeeIncludedTax");
        outerDesignChanges.setMoldTotalPrice(BigdecimalUtil.stringTo2DecimalString(moldFeeIncludedTax));
        //jsonobject解析获取客户设变费用
        String customerChanedFee = jsonObject.getString("customerChanedFee");
        outerDesignChanges.setOuterDesignChangePrice(BigdecimalUtil.stringTo2DecimalString(customerChanedFee));
        //jsonobject解析获取内部设变费用
        String innerChangedFee = jsonObject.getString("innerChangedFee");
        outerDesignChanges.setInnerDesignChangePrice(BigdecimalUtil.stringTo2DecimalString(innerChangedFee));
        //jsonobject解析获取客户设变占比
        String customerChanedRatio = jsonObject.getString("customerChanedRatio");
        outerDesignChanges.setOuterDesignChangeRatio(BigdecimalUtil.stringTo2DecimalString(customerChanedRatio));
        //jsonobject解析获取内部设变占比
        String innerChangedRatio = jsonObject.getString("innerChangedRatio");
        outerDesignChanges.setInnerDesignChangeRatio(BigdecimalUtil.stringTo2DecimalString(innerChangedRatio));
        //jsonobject解析获取拟制
        String projectManager = jsonObject.getString("projectManager");
        outerDesignChanges.setMaker(projectManager);
        //jsonobject解析获取项目控制室主任
        String directorOfControlRoom = jsonObject.getString("directorOfControlRoom");
        outerDesignChanges.setControlRoomDirector(directorOfControlRoom);
        //jsonobject解析获取项目经理
        String directorOfProject = jsonObject.getString("directorOfProject");
        outerDesignChanges.setManager(directorOfProject);
        //jsonobject解析获取项目分部主管领导
        String directorOfPartProject = jsonObject.getString("directorOfPartProject");
        outerDesignChanges.setLeader(directorOfPartProject);
        //jsonobject解析获取技术部部长
        String directorOfTechnology = jsonObject.getString("directorOfTechnology");
        outerDesignChanges.setMinister(directorOfTechnology);
        //jsonobject解析获取批准
        String approver = jsonObject.getString("approver");
        outerDesignChanges.setApprover(approver);
        //jsonobject解析获取备用参数1
        String param1 = jsonObject.getString("param1");
        outerDesignChanges.setParam1(param1);
        //jsonobject解析获取备用参数2
        String param2 = jsonObject.getString("param2");
        //jsonobject解析获取备用参数3
        String param3 = jsonObject.getString("param3");
        //jsonobject解析获取备用参数4
        String param4 = jsonObject.getString("param4");
        //jsonobject解析获取备用参数5
        String param5 = jsonObject.getString("param5");
        //jsonobject解析获取备用参数6
        String param6 = jsonObject.getString("param6");
        //jsonobject解析获取备用参数7
        String param7 = jsonObject.getString("param7");
        //jsonobject解析获取备用参数8
        String param8 = jsonObject.getString("param8");
        //jsonobject解析获取备用参数9
        String param9 = jsonObject.getString("param9");
        //jsonobject解析获取选模表Id
        String moldSelectionId = jsonObject.getString("moldSelectionId");
        outerDesignChanges.setMoldSelectionId(moldSelectionId);

        try {
            saveOutDesignChangeOrRollback(outerDesignChanges, dataList, moldSelectionId, request);
        } catch (RuntimeException e) {
            return JSON.toJSONString(R.fail(e.getMessage()));
        }
        return JSON.toJSONString(R.success("保存成功"));
    }

    @Override
    public String getDesignEditionInfo(JSONObject jsonObject) {
        //jsonobject解析获取每页条数
        int pageSize = jsonObject.getIntValue("pageSize");
        //jsonobject解析获取页码
        int pageNum = jsonObject.getIntValue("pageNum");
        //jsonobject解析获取id
        String id = jsonObject.getString("id");
        //jsonobject解析获取类别
        //1 内部设变 2 外部设变
        String type = jsonObject.getString("type");
        Page page = new Page<>(pageNum, pageSize);
        switch (type) {
            case "1":
                page = innerDesignChangesChangeMapper.selectPage(page,
                        new LambdaQueryWrapper<InnerDesignChangesChange>()
                                .eq(StringUtils.isNotEmpty(id), InnerDesignChangesChange::getMoldSelectionId, id)
                                .orderByAsc(InnerDesignChangesChange::getTime));
                break;
            case "2":
                page = outerDesignChangesChangeMapper.selectPage(page,
                        new LambdaQueryWrapper<OuterDesignChangesChange>()
                                .eq(StringUtils.isNotEmpty(id), OuterDesignChangesChange::getMoldSelectionId, id)
                                .orderByAsc(OuterDesignChangesChange::getTime));
                break;
        }
        JSONObject json = new JSONObject();
        json.put("dataList", page.getRecords());
        json.put("totalNum", page.getTotal());
        return JSON.toJSONString((R.data(json)));
//        if (
//                "1".equals(id)
//        ){
//            return "{\"data\":{\"数据列表\":[{\"updateBy\":\"wangxx\",\"edition\":\"V1\",\"updateTime\":\"2023-10-30 11:34:45\",\"updateContent\":\"将xxx 修改为 xxx\"}]}}";
//        }
//        return JSON.toJSONString(R.success("无数据"));
    }

    private void saveOutDesignChangeOrRollback(OuterDesignChanges outerDesignChanges, JSONArray dataList, String moldSelectionId, HttpServletRequest request) throws RuntimeException {
        //开启事务
        TransactionStatus status = transactionManager.getTransaction(new DefaultTransactionDefinition());
        try {
            for (int i = 0; i < dataList.size(); i++) {
                JSONObject jsonObject1 = dataList.getJSONObject(i);
                OuterDesignChangesDetail outerDesignChangesDetail = new OuterDesignChangesDetail();
                //是否审批
                String isApprove = jsonObject1.getString("isApprove");
                outerDesignChangesDetail.setIsApprove(isApprove);

                //产品技术通知单
                String productTechnicalNoteNum = jsonObject1.getString("productTechnicalNoteNum");
                outerDesignChangesDetail.setProductTechnicalNoticeNumber(productTechnicalNoteNum);

                //技术通知单号
                String technicalNoteNum = jsonObject1.getString("technicalNoteNum");
                outerDesignChangesDetail.setTechnicalNoticeNumber(technicalNoteNum);

                //模具编号(客户)
                String customerMoldId = jsonObject1.getString("customerMoldId");
                outerDesignChangesDetail.setMoldId(customerMoldId);

                //模具名称
                String moldName = jsonObject1.getString("moldName");
                outerDesignChangesDetail.setMoldName(moldName);

                //设变内容
                String changedContent = jsonObject1.getString("changedContent");
                outerDesignChangesDetail.setContent(changedContent);

                //设变时间
                String changedTime = jsonObject1.getString("changedTime");
                outerDesignChangesDetail.setTime(changedTime);

                //目标价
                JSONObject jsonObjectTargetFee = jsonObject1.getJSONObject("targetFee");

                //targetFee中的客户目标价和内部目标价
                String customerTargetFee = jsonObjectTargetFee.getString("customerTargetFee");
                outerDesignChangesDetail.setOuterDesignChangePrice(BigdecimalUtil.stringTo2DecimalString(customerTargetFee));
                String innerTargetFee = jsonObjectTargetFee.getString("innerTargetFee");
                outerDesignChangesDetail.setInnerDesignChangePrice(BigdecimalUtil.stringTo2DecimalString(innerTargetFee));

                //设变来源
                String changedSource = jsonObject1.getString("changedSource");
                outerDesignChangesDetail.setSource(changedSource);

                //设变类别
                String changedType = jsonObject1.getString("changedType");
                outerDesignChangesDetail.setType(changedType);

                //模具供应商
                String companyId = jsonObject1.getString("companyId");
                outerDesignChangesDetail.setSupplier(companyId);

                //供应商报价（含税元）
                String companyQuotationIncludeTax = jsonObject1.getString("companyQuotationIncludeTax");
                outerDesignChangesDetail.setSupplierFee(BigdecimalUtil.stringTo2DecimalString(companyQuotationIncludeTax));

                //模具费用（含税元）
                String moldFeeIncludedTaxObj1 = jsonObject1.getString("moldFeeIncludedTax");
                outerDesignChangesDetail.setMoldPrice(BigdecimalUtil.stringTo2DecimalString(moldFeeIncludedTaxObj1));

                //设变目标价占比
                String changedFeeRatio = jsonObject1.getString("changedFeeRatio");
                outerDesignChangesDetail.setDesignChangeRatio(BigdecimalUtil.stringTo2DecimalString(changedFeeRatio));

                //内部模具编号
                String moldId = jsonObject1.getString("moldId");
                outerDesignChangesDetail.setInnerMoldId(moldId);

                //选模Id
                outerDesignChangesDetail.setMoldSelectionId(moldSelectionId);

                //详情数据
                JSONObject jsonObjectdetail = jsonObject1.getJSONObject("detail");

                //设变内容
                String changedContentObjDetail = jsonObjectdetail.getString("changedContent");
                outerDesignChangesDetail.setContent(changedContent);

                //模具外形-宽
                String widthOfMold = jsonObjectdetail.getString("widthOfMold");
                outerDesignChangesDetail.setMoldWidth(BigdecimalUtil.stringToIntegerString(widthOfMold));

                //整改方案
                String remediationAction = jsonObjectdetail.getString("remediationAction");
                outerDesignChangesDetail.setRectificationPlan(remediationAction);

                //定义机台 Id
                String deviceId = jsonObjectdetail.getString("deviceId");
                outerDesignChangesDetail.setDeviceId(deviceId);

                //模具外形-高
                String heightOfMold = jsonObjectdetail.getString("heightOfMold");
                outerDesignChangesDetail.setMoldHeight(BigdecimalUtil.stringToIntegerString(heightOfMold));

                //项目名称
                String projectName = jsonObjectdetail.getString("projectName");
                outerDesignChangesDetail.setProjectName(projectName);

                //产品名称
                String productName = jsonObjectdetail.getString("productName");
                outerDesignChangesDetail.setProductName(productName);

                //设变单号
                String changedId = jsonObjectdetail.getString("changedId");
                outerDesignChangesDetail.setDesignChangesCode(changedId);

                //设变周期
                String changedPeriod = jsonObjectdetail.getString("changedPeriod");
                outerDesignChangesDetail.setChangedPeriod(changedPeriod);

                //模具名称
                String moldNameObjDetail = jsonObjectdetail.getString("moldName");
                outerDesignChangesDetail.setMoldName(moldName);

                //模具编号(客户)
                String customerMoldIdObjDetail = jsonObjectdetail.getString("customerMoldId");
                outerDesignChangesDetail.setMoldId(customerMoldId);

                //模具外形-长
                String lengthOfMold = jsonObjectdetail.getString("lengthOfMold");
                outerDesignChangesDetail.setMoldLength(BigdecimalUtil.stringToIntegerString(lengthOfMold));

                //供应商
                String supplier = jsonObjectdetail.getString("supplier");
                outerDesignChangesDetail.setSupplier(supplier);

                //供应商报价人签字
                String supplierContact = jsonObjectdetail.getString("supplierContact");
                outerDesignChangesDetail.setBidder(supplierContact);

                //合计
                String summation = jsonObjectdetail.getString("summation");
                outerDesignChangesDetail.setTotalFee(BigdecimalUtil.stringTo2DecimalString(summation));

                //拟制
                String projectManagerObjDetail = jsonObjectdetail.getString("projectManager");
                outerDesignChangesDetail.setMaker(projectManagerObjDetail);

                //审核
                String checkoutName = jsonObjectdetail.getString("checkoutName");
                outerDesignChangesDetail.setAuditor(checkoutName);

                //批准
                String approverObjDetail = jsonObjectdetail.getString("approver");
                outerDesignChangesDetail.setApprover(approverObjDetail);

                //定义机台名称
                String deviceName = jsonObjectdetail.getString("deviceName");
                outerDesignChangesDetail.setPress(deviceName);

                //主要费用核价明细
                String mainFeeCheck = jsonObjectdetail.getString("mainFeeCheck");
                outerDesignChangesDetail.setMainFeeCheck(BigdecimalUtil.stringTo2DecimalString(mainFeeCheck));

                //材料费用核价明细
                String materialFeeCheck = jsonObjectdetail.getString("materialFeeCheck");
                outerDesignChangesDetail.setMaterialFeeCheck(BigdecimalUtil.stringTo2DecimalString(materialFeeCheck));

                //合计核价明细
                String totalFeeCheck = jsonObjectdetail.getString("totalFeeCheck");
                outerDesignChangesDetail.setTotalFeeCheck(BigdecimalUtil.stringTo2DecimalString(totalFeeCheck));

                //分表Id
                String subTableId = jsonObject1.getString("subTableId");
                if (StringUtils.isNotEmpty(subTableId)) {
                    outerDesignChangesDetail.setId(subTableId);
                }

                //小计
                JSONObject jsonObjectTransportFee = jsonObjectdetail.getJSONObject("transportFeeObject");
                JSONObject jsonObjectTryoutFee = jsonObjectdetail.getJSONObject("tryoutFeeObject");
                JSONObject jsonObjectTestFee = jsonObjectdetail.getJSONObject("measureFeeObject");
                JSONObject jsonObjectMachiningFee = jsonObjectdetail.getJSONObject("processFeeObject");
                JSONObject jsonObjectDesignFee = jsonObjectdetail.getJSONObject("designFeeObject");
                JSONObject jsonObjectOtherFee = jsonObjectdetail.getJSONObject("otherFeeObject");
                JSONObject jsonObjectMaterialFee = jsonObjectdetail.getJSONObject("materialFeeObject");
                String subTotalTransportFee = jsonObjectTransportFee.getString("subTotal");
                String subTotalTryoutFee = jsonObjectTryoutFee.getString("subTotal");
                String subTotalTestFee = jsonObjectTestFee.getString("subTotal");
                String subTotalMachiningFee = jsonObjectMachiningFee.getString("subTotal");
                String subTotaldesignFee = jsonObjectDesignFee.getString("subTotal");
                String subTotalmaterialFee = jsonObjectMaterialFee.getString("subTotal");
                String subTotalOtherFee = jsonObjectOtherFee.getString("subTotal");
                //Detail表小计
                outerDesignChangesDetail.setDesignFeeTotal(BigdecimalUtil.stringTo2DecimalString(subTotaldesignFee));
                outerDesignChangesDetail.setOtherFeeTotal(BigdecimalUtil.stringTo2DecimalString(subTotalOtherFee));
                outerDesignChangesDetail.setMachiningFeeTotal(BigdecimalUtil.stringTo2DecimalString(subTotalMachiningFee));
                outerDesignChangesDetail.setMaterialFeeTotal(BigdecimalUtil.stringTo2DecimalString(subTotalmaterialFee));
                outerDesignChangesDetail.setTransportFeeTotal(BigdecimalUtil.stringTo2DecimalString(subTotalTransportFee));
                outerDesignChangesDetail.setTryoutFeeTotal(BigdecimalUtil.stringTo2DecimalString(subTotalTryoutFee));
                outerDesignChangesDetail.setTestFeeTotal(BigdecimalUtil.stringTo2DecimalString(subTotalTestFee));

                //比对CheckFee
                JSONArray materialFeeDataList = jsonObjectMaterialFee.getJSONArray("dataList");
                JSONArray otherFeeDataList = jsonObjectOtherFee.getJSONArray("dataList");
                BigDecimal mainFeeCheckCnt = getMainFeeCheck(jsonObjectdetail);
                BigDecimal materialFeeCheakCnt = getFeeCheck(materialFeeDataList);
                BigDecimal otherFeeCheckCnt = getFeeCheck(otherFeeDataList);
                BigDecimal totalFeeCheckCnt = mainFeeCheckCnt.add(materialFeeCheakCnt).add(otherFeeCheckCnt);
                if (BigdecimalUtil.stringToBigDecimal(mainFeeCheck).compareTo(mainFeeCheckCnt) != 0 ||
                        BigdecimalUtil.stringToBigDecimal(materialFeeCheck).compareTo(materialFeeCheakCnt) != 0 ||
                        BigdecimalUtil.stringToBigDecimal(totalFeeCheck).compareTo(totalFeeCheckCnt) != 0) {
                    throw new RuntimeException("费用明细核查错误");
                }
                boolean boolOuterDesignChangesDetail = iOuterDesignChangesDetailService
                        .saveOrUpdate(outerDesignChangesDetail, new LambdaUpdateWrapper<OuterDesignChangesDetail>()
                                .eq(OuterDesignChangesDetail::getId, outerDesignChangesDetail.getId()));
                if (!boolOuterDesignChangesDetail) {
                    throw new RuntimeException("外部设变详情保存失败");
                }
                //重新获取分表id
                subTableId = outerDesignChangesDetail.getId();

                //保存运输费用
                JSONArray transportFeeDataList = jsonObjectTransportFee.getJSONArray("dataList");
                if (!savePrice(transportFeeDataList, "运输费用", moldSelectionId, subTableId, subTotalTransportFee)) {
                    throw new RuntimeException("运输费用价格表保存失败");
                }

                //保存试模费用
                JSONArray tryoutFeeDataList = jsonObjectTryoutFee.getJSONArray("dataList");
                if (!savePrice(tryoutFeeDataList, "试模费用", moldSelectionId, subTableId, subTotalTryoutFee)) {
                    throw new RuntimeException("试模费用价格表保存失败");
                }

                //保存检测费用
                JSONArray testFeeDataList = jsonObjectTestFee.getJSONArray("dataList");
                if (!savePrice(testFeeDataList, "检测费用", moldSelectionId, subTableId, subTotalTestFee)) {
                    throw new RuntimeException("检测费用价格表保存失败");
                }

                //保存加工费用
                JSONArray machiningFeeDataList = jsonObjectMachiningFee.getJSONArray("dataList");
                if (!savePrice(machiningFeeDataList, "加工费用", moldSelectionId, subTableId, subTotalMachiningFee)) {
                    throw new RuntimeException("加工费用价格表保存失败");
                }

                //保存设计费用
                JSONArray designFeeDataList = jsonObjectDesignFee.getJSONArray("dataList");
                if (!savePrice(designFeeDataList, "设计费用", moldSelectionId, subTableId, subTotaldesignFee)) {
                    throw new RuntimeException("设计费用价格表保存失败");
                }

                //保存材料费用
                if (!savePrice(materialFeeDataList, "材料费用", moldSelectionId, subTableId, subTotalmaterialFee)) {
                    throw new RuntimeException("材料费用价格表保存失败");
                }

                //保存其他费用
                BigDecimal subTotalTotal = BigdecimalUtil.stringToBigDecimal(subTotalTransportFee)
                        .add(BigdecimalUtil.stringToBigDecimal(subTotalTryoutFee))
                        .add(BigdecimalUtil.stringToBigDecimal(subTotalTestFee))
                        .add(BigdecimalUtil.stringToBigDecimal(subTotalMachiningFee))
                        .add(BigdecimalUtil.stringToBigDecimal(subTotaldesignFee))
                        .add(BigdecimalUtil.stringToBigDecimal(subTotalmaterialFee));
                if (!savePriceOtherFee(otherFeeDataList, "其它费用", moldSelectionId, subTableId, subTotalOtherFee, subTotalTotal)) {
                    throw new RuntimeException("其它费用价格表保存失败");
                }
            }

            OuterDesignChanges one = iOuterDesignChangesService.getOne(new LambdaUpdateWrapper<OuterDesignChanges>().eq(OuterDesignChanges::getMoldSelectionId, moldSelectionId));
            Integer version;
            if (ObjectUtil.isEmpty(one)) {
                version = 1;
                outerDesignChanges.setVersion(version);
                iOuterDesignChangesService.save(outerDesignChanges);
            } else {
                version = one.getVersion() + 1;
                outerDesignChanges.setVersion(version);
                boolean boolOuterDesignChanges = iOuterDesignChangesService
                        .update(outerDesignChanges, new LambdaUpdateWrapper<OuterDesignChanges>().eq(OuterDesignChanges::getMoldSelectionId, moldSelectionId));
                if (!boolOuterDesignChanges) {
                    throw new RuntimeException("外部设变表保存失败");
                }
            }
            String id = MyUtils.getHeader(request).getId();
            String name = MyUtils.getName(id);
            OuterDesignChangesChange outerDesignChangesChange = new OuterDesignChangesChange();
            outerDesignChangesChange.setTime(LocalDateTime.now());
            outerDesignChangesChange.setVersion(version);
            outerDesignChangesChange.setUpdateById(id);
            outerDesignChangesChange.setUpdateByName(name);
            outerDesignChangesChange.setMoldSelectionId(moldSelectionId);
            outerDesignChangesChangeMapper.insert(outerDesignChangesChange);
            transactionManager.commit(status);
        } catch (RuntimeException e) {
            transactionManager.rollback(status);
            throw e;
        }
    }

    @Override
    public String getOutDesignChange(JSONObject jsonObject) {
        //jsonobject解析获取选模表Id
        String moldSelectionId = jsonObject.getString("moldSelectionId");
        //jsonobject解析获取是否审批
        String isApprove = jsonObject.getString("isApprove");
        JSONObject userInfoJson = new JSONObject();
        OuterDesignChanges outerDesignChanges = outerDesignChangesMapper
                .selectOne(new LambdaQueryWrapper<OuterDesignChanges>()
                        .eq(OuterDesignChanges::getMoldSelectionId, moldSelectionId));
        List<OuterDesignChangesDetail> outerDesignChangesDetailList = outerDesignChangesDetailMapper
                .selectList(new LambdaQueryWrapper<OuterDesignChangesDetail>()
                        .eq(OuterDesignChangesDetail::getMoldSelectionId, moldSelectionId)
                        .eq(StringUtils.isNotEmpty(isApprove), OuterDesignChangesDetail::getIsApprove, isApprove)
                        .orderByAsc(OuterDesignChangesDetail::getMoldId));
        List<OuterDesignChangesDetaiVo> outerDesignChangesDetaiVoList = new ArrayList<OuterDesignChangesDetaiVo>();

        for (OuterDesignChangesDetail outerDesignChangesDetail : outerDesignChangesDetailList) {
            //建outerDesignChangesDetaiVo并赋值
            OuterDesignChangesDetaiVo outerDesignChangesDetaiVo = new OuterDesignChangesDetaiVo();
            if (StringUtils.isNotEmpty(outerDesignChangesDetail.getIsApprove()))
                outerDesignChangesDetaiVo.setIsApprove(outerDesignChangesDetail.getIsApprove());
            if (StringUtils.isNotEmpty(outerDesignChangesDetail.getProductTechnicalNoticeNumber()))
                outerDesignChangesDetaiVo.setProductTechnicalNoteNum(outerDesignChangesDetail.getProductTechnicalNoticeNumber());
            if (StringUtils.isNotEmpty(outerDesignChangesDetail.getTechnicalNoticeNumber()))
                outerDesignChangesDetaiVo.setTechnicalNoteNum(outerDesignChangesDetail.getTechnicalNoticeNumber());
            if (StringUtils.isNotEmpty(outerDesignChangesDetail.getMoldId()))
                outerDesignChangesDetaiVo.setCustomerMoldId(outerDesignChangesDetail.getMoldId());
            if (StringUtils.isNotEmpty(outerDesignChangesDetail.getMoldName()))
                outerDesignChangesDetaiVo.setMoldName(outerDesignChangesDetail.getMoldName());
            if (StringUtils.isNotEmpty(outerDesignChangesDetail.getContent()))
                outerDesignChangesDetaiVo.setChangedContent(outerDesignChangesDetail.getContent());
            if (StringUtils.isNotEmpty(outerDesignChangesDetail.getTime()))
                outerDesignChangesDetaiVo.setChangedTime(outerDesignChangesDetail.getTime());
            //建targetFee对象封装数据
            TargetFeeVo targetFeeVo = new TargetFeeVo();
            if (StringUtils.isNotEmpty(outerDesignChangesDetail.getOuterDesignChangePrice()))
                targetFeeVo.setCustomerTargetFee(MyUtils.formatDouble(outerDesignChangesDetail.getOuterDesignChangePrice()));
            else targetFeeVo.setCustomerTargetFee(0.00);
            if (StringUtils.isNotEmpty(outerDesignChangesDetail.getInnerDesignChangePrice()))
                targetFeeVo.setInnerTargetFee(MyUtils.formatDouble(outerDesignChangesDetail.getInnerDesignChangePrice()));
            else targetFeeVo.setInnerTargetFee(0.00);
            outerDesignChangesDetaiVo.setTargetFee(targetFeeVo);
            if (StringUtils.isNotEmpty(outerDesignChangesDetail.getSource()))
                outerDesignChangesDetaiVo.setChangedSource(outerDesignChangesDetail.getSource());
            if (StringUtils.isNotEmpty(outerDesignChangesDetail.getType()))
                outerDesignChangesDetaiVo.setChangedType(outerDesignChangesDetail.getType());
            if (StringUtils.isNotEmpty(outerDesignChangesDetail.getSupplier()))
                outerDesignChangesDetaiVo.setCompanyId(outerDesignChangesDetail.getSupplier());
            if (StringUtils.isNotEmpty(outerDesignChangesDetail.getSupplierFee()))
                outerDesignChangesDetaiVo.setCompanyQuotationIncludeTax(outerDesignChangesDetail.getSupplierFee());
            if (StringUtils.isNotEmpty(outerDesignChangesDetail.getMoldPrice()))
                outerDesignChangesDetaiVo.setMoldFeeIncludedTax(outerDesignChangesDetail.getMoldPrice());
            if (StringUtils.isNotEmpty(outerDesignChangesDetail.getDesignChangeRatio()))
                outerDesignChangesDetaiVo.setChangedFeeRatio(outerDesignChangesDetail.getDesignChangeRatio());
            if (StringUtils.isNotEmpty(outerDesignChangesDetail.getMoldId()))
                outerDesignChangesDetaiVo.setMoldId(outerDesignChangesDetail.getMoldId());
            OutDetailVo outdetailVo = new OutDetailVo();
            if (StringUtils.isNotEmpty(outerDesignChangesDetail.getPress()))
                outdetailVo.setDeviceName(outerDesignChangesDetail.getPress());
            if (StringUtils.isNotEmpty(outerDesignChangesDetail.getContent()))
                outdetailVo.setChangedContent(outerDesignChangesDetail.getContent());
            if (StringUtils.isNotEmpty(outerDesignChangesDetail.getDeviceId()))
                outdetailVo.setDeviceId(outerDesignChangesDetail.getDeviceId());
            if (StringUtils.isNotEmpty(outerDesignChangesDetail.getMoldHeight()))
                outdetailVo.setHeightOfMold(outerDesignChangesDetail.getMoldHeight());
            if (StringUtils.isNotEmpty(outerDesignChangesDetail.getProjectName()))
                outdetailVo.setProjectName(outerDesignChangesDetail.getProjectName());
            if (StringUtils.isNotEmpty(outerDesignChangesDetail.getProductName()))
                outdetailVo.setProductName(outerDesignChangesDetail.getProductName());
            if (StringUtils.isNotEmpty(outerDesignChangesDetail.getDesignChangesCode()))
                outdetailVo.setChangedId(outerDesignChangesDetail.getDesignChangesCode());
            if (StringUtils.isNotEmpty(outerDesignChangesDetail.getChangedPeriod()))
                outdetailVo.setChangedPeriod(outerDesignChangesDetail.getChangedPeriod());
            if (StringUtils.isNotEmpty(outerDesignChangesDetail.getMoldName()))
                outdetailVo.setMoldName(outerDesignChangesDetail.getMoldName());
            if (StringUtils.isNotEmpty(outerDesignChangesDetail.getMoldId()))
                outdetailVo.setCustomerMoldId(outerDesignChangesDetail.getMoldId());
            if (StringUtils.isNotEmpty(outerDesignChangesDetail.getMoldLength()))
                outdetailVo.setLengthOfMold(outerDesignChangesDetail.getMoldLength());
            if (StringUtils.isNotEmpty(outerDesignChangesDetail.getMoldWidth()))
                outdetailVo.setWidthOfMold(outerDesignChangesDetail.getMoldWidth());
            if (StringUtils.isNotEmpty(outerDesignChangesDetail.getRectificationPlan()))
                outdetailVo.setRemediationAction(outerDesignChangesDetail.getRectificationPlan());
            outdetailVo.setDesignFeeObject(getOutFeeVo(moldSelectionId, outerDesignChangesDetail.getId(), "设计费用"));
            outdetailVo.setMaterialFeeObject(getMaterialFeeVo(moldSelectionId, outerDesignChangesDetail.getId(), "材料费用"));
            outdetailVo.setProcessFeeObject(getOutFeeVo(moldSelectionId, outerDesignChangesDetail.getId(), "加工费用"));
            outdetailVo.setMeasureFeeObject(getOutFeeVo(moldSelectionId, outerDesignChangesDetail.getId(), "检测费用"));
            outdetailVo.setTryoutFeeObject(getOutFeeVo(moldSelectionId, outerDesignChangesDetail.getId(), "试模费用"));
            outdetailVo.setTransportFeeObject(getOutFeeVo(moldSelectionId, outerDesignChangesDetail.getId(), "运输费用"));
            outdetailVo.setOtherFeeObject(getOtherFeeVo(moldSelectionId, outerDesignChangesDetail.getId(), "其它费用"));
            if (StringUtils.isNotEmpty(outerDesignChangesDetail.getSupplier()))
                outdetailVo.setSupplier(outerDesignChangesDetail.getSupplier());
            if (StringUtils.isNotEmpty(outerDesignChangesDetail.getBidder()))
                outdetailVo.setSupplierContact(outerDesignChangesDetail.getBidder());
            if (StringUtils.isNotEmpty(outerDesignChangesDetail.getTime()))
                outdetailVo.setAddtime(outerDesignChangesDetail.getTime());
            if (StringUtils.isNotEmpty(outerDesignChangesDetail.getTotalFee()))
                outdetailVo.setSummation(outerDesignChangesDetail.getTotalFee());
            if (StringUtils.isNotEmpty(outerDesignChangesDetail.getMaker()))
                outdetailVo.setProjectManager(outerDesignChangesDetail.getMaker());
            if (StringUtils.isNotEmpty(outerDesignChangesDetail.getAuditor()))
                outdetailVo.setCheckoutName(outerDesignChangesDetail.getAuditor());
            if (StringUtils.isNotEmpty(outerDesignChangesDetail.getApprover()))
                outdetailVo.setApprover(outerDesignChangesDetail.getApprover());
            if (StringUtils.isNotEmpty(outerDesignChangesDetail.getMainFeeCheck()))
                outdetailVo.setMainFeeCheck(MyUtils.formatDouble(outerDesignChangesDetail.getMainFeeCheck()));
            else outdetailVo.setMainFeeCheck(0.00);
            if (StringUtils.isNotEmpty(outerDesignChangesDetail.getMaterialFeeCheck()))
                outdetailVo.setMaterialFeeCheck(MyUtils.formatDouble(outerDesignChangesDetail.getMaterialFeeCheck()));
            else outdetailVo.setMaterialFeeCheck(0.00);
            if (StringUtils.isNotEmpty(outerDesignChangesDetail.getTotalFeeCheck()))
                outdetailVo.setTotalFeeCheck(MyUtils.formatDouble(outerDesignChangesDetail.getTotalFeeCheck()));
            else outdetailVo.setTotalFeeCheck(0.00);
            outerDesignChangesDetaiVo.setDetail(outdetailVo);
            outerDesignChangesDetaiVo.setSubTableId(outerDesignChangesDetail.getId());
            outerDesignChangesDetaiVoList.add(outerDesignChangesDetaiVo);
        }
        if (outerDesignChanges != null) {
            if (StringUtils.isNotEmpty(outerDesignChanges.getDesignChangeRatio()))
                userInfoJson.put("chanedRatio", outerDesignChanges.getDesignChangeRatio());
            else userInfoJson.put("chanedRatio", 0.00);
            if (StringUtils.isNotEmpty(outerDesignChanges.getSupplierFeeTotal()))
                userInfoJson.put("totalFee", outerDesignChanges.getSupplierFeeTotal());
            else userInfoJson.put("totalFee", 0.00);
            if (StringUtils.isNotEmpty(outerDesignChanges.getDesignChangePrice()))
                userInfoJson.put("chanedFee", outerDesignChanges.getDesignChangePrice());
            else userInfoJson.put("chanedFee", 0.00);
            if (StringUtils.isNotEmpty(outerDesignChanges.getMoldTotalPrice()))
                userInfoJson.put("moldFeeIncludedTax", outerDesignChanges.getMoldTotalPrice());
            else userInfoJson.put("moldFeeIncludedTax", 0.00);
            if (StringUtils.isNotEmpty(outerDesignChanges.getOuterDesignChangePrice()))
                userInfoJson.put("customerChanedFee", outerDesignChanges.getOuterDesignChangePrice());
            else userInfoJson.put("customerChanedFee", 0.00);
            if (StringUtils.isNotEmpty(outerDesignChanges.getInnerDesignChangePrice()))
                userInfoJson.put("innerChangedFee", outerDesignChanges.getInnerDesignChangePrice());
            else userInfoJson.put("innerChangedFee", 0.00);
            if (StringUtils.isNotEmpty(outerDesignChanges.getOuterDesignChangeRatio()))
                userInfoJson.put("customerChanedRatio", outerDesignChanges.getOuterDesignChangeRatio());
            else userInfoJson.put("customerChanedRatio", "");
            if (StringUtils.isNotEmpty(outerDesignChanges.getInnerDesignChangeRatio()))
                userInfoJson.put("innerChangedRatio", outerDesignChanges.getInnerDesignChangeRatio());
            else userInfoJson.put("innerChangedRatio", "");
            if (StringUtils.isNotEmpty(outerDesignChanges.getMaker()))
                userInfoJson.put("projectManager", outerDesignChanges.getMaker());
            else userInfoJson.put("projectManager", "");
            if (StringUtils.isNotEmpty(outerDesignChanges.getControlRoomDirector()))
                userInfoJson.put("directorOfControlRoom", outerDesignChanges.getControlRoomDirector());
            else userInfoJson.put("directorOfControlRoom", "");
            if (StringUtils.isNotEmpty(outerDesignChanges.getManager()))
                userInfoJson.put("directorOfProject", outerDesignChanges.getManager());
            else userInfoJson.put("directorOfProject", "");
            if (StringUtils.isNotEmpty(outerDesignChanges.getLeader()))
                userInfoJson.put("directorOfPartProject", outerDesignChanges.getLeader());
            else userInfoJson.put("directorOfPartProject", "");
            if (StringUtils.isNotEmpty(outerDesignChanges.getMinister()))
                userInfoJson.put("directorOfTechnology", outerDesignChanges.getMinister());
            else userInfoJson.put("directorOfTechnology", "");
            if (StringUtils.isNotEmpty(outerDesignChanges.getApprover()))
                userInfoJson.put("approver", outerDesignChanges.getApprover());
            else userInfoJson.put("approver", "");
            if (StringUtils.isNotEmpty(outerDesignChanges.getParam1()))
                userInfoJson.put("param1", outerDesignChanges.getParam1());
            else userInfoJson.put("param1", "");
        }
        if (outerDesignChanges == null && outerDesignChangesDetailList.size() != 0) {
            userInfoJson.put("chanedRatio", "");
            userInfoJson.put("totalFee", 0.00);
            userInfoJson.put("chanedFee", 0.00);
            userInfoJson.put("moldFeeIncludedTax", 0.00);
            userInfoJson.put("customerChanedFee", 0.00);
            userInfoJson.put("innerChangedFee", 0.00);
            userInfoJson.put("customerChanedRatio", "");
            userInfoJson.put("innerChangedRatio", "");
            userInfoJson.put("projectManager", "");
            userInfoJson.put("directorOfControlRoom", "");
            userInfoJson.put("directorOfProject", "");
            userInfoJson.put("directorOfPartProject", "");
            userInfoJson.put("directorOfTechnology", "");
            userInfoJson.put("approver", "");
            userInfoJson.put("param1", "");
        }
        //if (outerDesignChangesDetailList.size()!=0){
        userInfoJson.put("moldSelectionId", moldSelectionId);
        userInfoJson.put("dataList", outerDesignChangesDetaiVoList);
        userInfoJson.put("version", outerDesignChanges.getVersion());
        //}


        return JSON.toJSONString(R.data(userInfoJson));
    }

    @Override
    public String deleteOutDesignChangeSubTableById(JSONObject jsonObject, HttpServletRequest request) {
        //jsonobject解析获取选模表Id
        String moldSelectionId = jsonObject.getString("moldSelectionId");
        //jsonobject解析获取分表Id
        String subTableId = jsonObject.getString("subTableId");

        //开启事务
        TransactionStatus status = transactionManager.getTransaction(new DefaultTransactionDefinition());
        try {
            //删除详情表数据
            int isOuterDesignChangesDetailDelete = outerDesignChangesDetailMapper
                    .delete(new LambdaQueryWrapper<OuterDesignChangesDetail>()
                            .eq(OuterDesignChangesDetail::getMoldSelectionId, moldSelectionId)
                            .eq(OuterDesignChangesDetail::getId, subTableId));
            //删除价格表数据
            int isOuterDesignChangePriceDelete = outerDesignChangePriceMapper
                    .delete(new LambdaQueryWrapper<OuterDesignChangePrice>()
                            .eq(OuterDesignChangePrice::getMoldSelectionId, moldSelectionId)
                            .eq(OuterDesignChangePrice::getDesignChangeId, subTableId));
            if (isOuterDesignChangePriceDelete == 0 || isOuterDesignChangesDetailDelete == 0) {
                throw new RuntimeException("删除失败");
            }

            OuterDesignChanges outerDesignChanges = outerDesignChangesMapper
                    .selectOne(new LambdaQueryWrapper<OuterDesignChanges>()
                            .eq(OuterDesignChanges::getMoldSelectionId, moldSelectionId));
            if (ObjectUtil.isNotEmpty(outerDesignChanges)) {
                int version = outerDesignChanges.getVersion() + 1;
                List<OuterDesignChangesDetail> outerDesignChangesDetailList = outerDesignChangesDetailMapper
                        .selectList(new LambdaQueryWrapper<OuterDesignChangesDetail>()
                                .eq(OuterDesignChangesDetail::getMoldSelectionId, moldSelectionId));
                BigDecimal supplierFeeTotal = new BigDecimal("0");
                BigDecimal moldTotalPrice = new BigDecimal("0");
                BigDecimal outerDesignChangePrice = new BigDecimal("0");
                BigDecimal innerDesignChangePrice = new BigDecimal("0");
                for (OuterDesignChangesDetail outerDesignChangesDetail : outerDesignChangesDetailList) {
                    supplierFeeTotal = supplierFeeTotal.add(BigdecimalUtil.stringToBigDecimal(outerDesignChangesDetail.getSupplierFee()));
                    moldTotalPrice = moldTotalPrice.add(BigdecimalUtil.stringToBigDecimal(outerDesignChangesDetail.getMoldPrice()));
                    outerDesignChangePrice = outerDesignChangePrice.add(BigdecimalUtil.stringToBigDecimal(outerDesignChangesDetail.getOuterDesignChangePrice()));
                    innerDesignChangePrice = innerDesignChangePrice.add(BigdecimalUtil.stringToBigDecimal(outerDesignChangesDetail.getInnerDesignChangePrice()));
                }
                BigDecimal designChangePrice = outerDesignChangePrice.add(innerDesignChangePrice);
                BigDecimal outerDesignChangeRatio = outerDesignChangePrice.divide(moldTotalPrice, 2, RoundingMode.HALF_UP);
                BigDecimal innerDesignChangeRatio = innerDesignChangePrice.divide(moldTotalPrice, 2, RoundingMode.HALF_UP);
                BigDecimal designChangeRatio = designChangePrice.divide(moldTotalPrice, 2, RoundingMode.HALF_UP);
                outerDesignChanges.setSupplierFeeTotal(BigdecimalUtil.bigDecimalTo2DecimalString(supplierFeeTotal));
                outerDesignChanges.setMoldTotalPrice(BigdecimalUtil.bigDecimalTo2DecimalString(moldTotalPrice));
                outerDesignChanges.setOuterDesignChangePrice(BigdecimalUtil.bigDecimalTo2DecimalString(outerDesignChangePrice));
                outerDesignChanges.setInnerDesignChangePrice(BigdecimalUtil.bigDecimalTo2DecimalString(innerDesignChangePrice));
                outerDesignChanges.setOuterDesignChangeRatio(BigdecimalUtil.bigDecimalTo2DecimalString(outerDesignChangeRatio));
                outerDesignChanges.setInnerDesignChangeRatio(BigdecimalUtil.bigDecimalTo2DecimalString(innerDesignChangeRatio));
                outerDesignChanges.setDesignChangePrice(BigdecimalUtil.bigDecimalTo2DecimalString(designChangePrice));
                outerDesignChanges.setDesignChangeRatio(BigdecimalUtil.bigDecimalTo2DecimalString(designChangeRatio));
                outerDesignChanges.setVersion(version);
                outerDesignChangesMapper.update(outerDesignChanges, new LambdaUpdateWrapper<OuterDesignChanges>().eq(OuterDesignChanges::getMoldSelectionId, moldSelectionId));
                String id = MyUtils.getHeader(request).getId();
                String name = MyUtils.getName(id);
                OuterDesignChangesChange outerDesignChangesChange = new OuterDesignChangesChange();
                outerDesignChangesChange.setTime(LocalDateTime.now());
                outerDesignChangesChange.setVersion(version);
                outerDesignChangesChange.setUpdateById(id);
                outerDesignChangesChange.setUpdateByName(name);
                outerDesignChangesChange.setMoldSelectionId(moldSelectionId);
                outerDesignChangesChangeMapper.insert(outerDesignChangesChange);
            }
            //提交事务
            transactionManager.commit(status);
        } catch (RuntimeException e) {
            //回滚事务
            transactionManager.rollback(status);
            return JSON.toJSONString(R.fail(e.getMessage()));
        }
        return JSON.toJSONString(R.success("删除成功"));
    }

    private OutFeeVo getOutFeeVo(String moldId, String detailId, String type) {
        List<OuterDesignChangePrice> typeFeeList = outerDesignChangePriceMapper
                .selectList(new LambdaQueryWrapper<OuterDesignChangePrice>()
                        .eq(OuterDesignChangePrice::getMoldSelectionId, moldId)
                        .eq(OuterDesignChangePrice::getDesignChangeId, detailId)
                        .eq(OuterDesignChangePrice::getType, type));
        //建itemPriceVo对象并赋值
        List<ItemPriceVo> itemPriceVoList = new ArrayList<ItemPriceVo>();
        //计算设计费用小计
        BigDecimal subTotal = new BigDecimal("0");
        for (OuterDesignChangePrice typeFee : typeFeeList) {
            subTotal = subTotal.add(BigdecimalUtil.double2BigDecimal2Decimal(MyUtils.formatDouble(typeFee.getTotalPrice())));
            ItemPriceVo itemPriceVo = new ItemPriceVo();

            if (StringUtils.isNotEmpty(typeFee.getId())) itemPriceVo.setId(typeFee.getId());

            if (typeFee.getPrice() != null) itemPriceVo.setPrice(MyUtils.formatDouble(typeFee.getPrice()));
            else itemPriceVo.setPrice(0);

            if (typeFee.getTotalPrice() != null)
                itemPriceVo.setTotalPrice(MyUtils.formatDouble(typeFee.getTotalPrice()));
            else itemPriceVo.setTotalPrice(0);

            if (StringUtils.isNotEmpty(typeFee.getName())) itemPriceVo.setItemName(typeFee.getName());

            if (typeFee.getNum() != null) itemPriceVo.setHour(MyUtils.formatDouble(typeFee.getNum()));
            else itemPriceVo.setHour(0);

            if (typeFee.getCheckPrice() != null)
                itemPriceVo.setCheckPrice(MyUtils.formatDouble(typeFee.getCheckPrice()));
            else itemPriceVo.setCheckPrice(0);
            itemPriceVoList.add(itemPriceVo);
        }
        //建designFeeVo对象并赋值
        OutFeeVo outFeeVo = new OutFeeVo();
        outFeeVo.setSubTotal(subTotal.doubleValue());
        outFeeVo.setDataList(itemPriceVoList);
        return outFeeVo;
    }

    private MaterialFeeVo getMaterialFeeVo(String moldId, String detailId, String type) {
        List<OuterDesignChangePrice> marialList = outerDesignChangePriceMapper
                .selectList(new LambdaQueryWrapper<OuterDesignChangePrice>()
                        .eq(OuterDesignChangePrice::getMoldSelectionId, moldId)
                        .eq(OuterDesignChangePrice::getDesignChangeId, detailId)
                        .eq(OuterDesignChangePrice::getType, type));
        //建MaterialItemVo列表对象并赋值
        List<MaterialFeeItemVo> materialFeeItemVoList = new ArrayList<MaterialFeeItemVo>();
        //计算费用小计
        BigDecimal subTotal = new BigDecimal("0");
        for (OuterDesignChangePrice marialFee : marialList) {
            subTotal = subTotal.add(BigdecimalUtil.double2BigDecimal2Decimal(MyUtils.formatDouble(marialFee.getTotalPrice())));
            MaterialFeeItemVo materialFeeItemVo = new MaterialFeeItemVo();

            if (StringUtils.isNotEmpty(marialFee.getId())) materialFeeItemVo.setId(marialFee.getId());

            if (marialFee.getPrice() != null) materialFeeItemVo.setPrice(MyUtils.formatDouble(marialFee.getPrice()));
            else materialFeeItemVo.setPrice(0);

            if (marialFee.getTotalPrice() != null)
                materialFeeItemVo.setTotalPrice(MyUtils.formatDouble(marialFee.getTotalPrice()));
            else materialFeeItemVo.setTotalPrice(0);

            if (StringUtils.isNotEmpty(marialFee.getName())) materialFeeItemVo.setItemName(marialFee.getName());

            if (StringUtils.isNotEmpty(marialFee.getSpecification()))
                materialFeeItemVo.setBrand(marialFee.getSpecification());

            if (marialFee.getCheckPrice() != null)
                materialFeeItemVo.setCheckPrice(MyUtils.formatDouble(marialFee.getCheckPrice()));
            else materialFeeItemVo.setCheckPrice(0);

            if (marialFee.getLength() != null)
                materialFeeItemVo.setLengthOfspecification(MyUtils.formatDouble(marialFee.getLength()));
            else materialFeeItemVo.setLengthOfspecification(0);

            if (marialFee.getWidth() != null)
                materialFeeItemVo.setWidthOfspecification(MyUtils.formatDouble(marialFee.getWidth()));
            else materialFeeItemVo.setWidthOfspecification(0);

            if (marialFee.getHeight() != null)
                materialFeeItemVo.setHeightOfspecification(MyUtils.formatDouble(marialFee.getHeight()));
            else materialFeeItemVo.setHeightOfspecification(0);

            if (StringUtils.isNotEmpty(marialFee.getNum())) {
                materialFeeItemVo.setWeight(MyUtils.formatDouble(marialFee.getNum()));
            } else {
                materialFeeItemVo.setWeight(0);
            }

            materialFeeItemVoList.add(materialFeeItemVo);
        }
        //建designFeeVo对象并赋值
        MaterialFeeVo materialFeeVo = new MaterialFeeVo();
        materialFeeVo.setSubTotal(subTotal.doubleValue());
        materialFeeVo.setDataList(materialFeeItemVoList);
        return materialFeeVo;
    }

    private OtherFeeVo getOtherFeeVo(String moldId, String detailId, String type) {
        List<OuterDesignChangePrice> list = outerDesignChangePriceMapper
                .selectList(new LambdaQueryWrapper<OuterDesignChangePrice>()
                        .eq(OuterDesignChangePrice::getMoldSelectionId, moldId)
                        .eq(OuterDesignChangePrice::getDesignChangeId, detailId)
                        .eq(OuterDesignChangePrice::getType, type));
        //建MaterialItemVo列表对象并赋值
        List<OtherFeeItemVo> itemList = new ArrayList<OtherFeeItemVo>();
        //计算费用小计
        BigDecimal cnt = new BigDecimal("0");
        for (OuterDesignChangePrice pFee : list) {
            if (pFee.getTotalPrice() != null) cnt = cnt.add(BigdecimalUtil.stringToBigDecimal(pFee.getTotalPrice()));
            OtherFeeItemVo item = new OtherFeeItemVo();
            if (StringUtils.isNotEmpty(pFee.getId())) item.setId(pFee.getId());
            if (StringUtils.isNotEmpty(pFee.getName())) item.setItemName(pFee.getName());
            if (pFee.getTotalPrice() != null) item.setTotalPrice(MyUtils.formatDouble(pFee.getTotalPrice()));
            else item.setTotalPrice(0);
            if (StringUtils.isNotEmpty(pFee.getNum())) item.setRatio(pFee.getNum());
            if (pFee.getCheckPrice() != null) item.setCheckPrice(MyUtils.formatDouble(pFee.getCheckPrice()));
            else item.setCheckPrice(0);
            itemList.add(item);
        }
        //建designFeeVo对象并赋值
        OtherFeeVo otherFeeVo = new OtherFeeVo();
        otherFeeVo.setSubTotal(cnt.doubleValue());
        otherFeeVo.setDataList(itemList);
        return otherFeeVo;
    }

    private void setExcel(XSSFWorkbook sheets, OuterDesignChanges outerDesignChanges, List<OuterDesignChangesDetail> outerDesignChangesDetailList) {
        XSSFSheet sheetAt;
        XSSFRow row;
        int sheetAtFirstRowNum = 10;//从11行开始
        int detailNum = outerDesignChangesDetailList.size();
        //处理每条detail数据
        for (int i = 0; i < detailNum; i++) {
            //总表页
            sheetAt = sheets.getSheetAt(0);
            int rownum = sheetAtFirstRowNum + i;
            OuterDesignChangesDetail outerDesignChangesDetail = outerDesignChangesDetailList.get(i);
            XSSFCell cell;
            cell = getOrCreateCell(sheetAt, rownum, 1);
            cell.setCellValue(outerDesignChangesDetail.getMoldName());
            cell = getOrCreateCell(sheetAt, rownum, 2);
            cell.setCellValue(outerDesignChangesDetail.getMoldId());
            cell = getOrCreateCell(sheetAt, rownum, 3);
            cell.setCellValue(outerDesignChangesDetail.getTechnicalNoticeNumber());
            cell = getOrCreateCell(sheetAt, rownum, 4);
            cell.setCellValue(outerDesignChangesDetail.getProductTechnicalNoticeNumber());
            cell = getOrCreateCell(sheetAt, rownum, 5);
            cell.setCellValue(outerDesignChangesDetail.getContent());
            cell = getOrCreateCell(sheetAt, rownum, 6);
            cell.setCellValue(outerDesignChangesDetail.getTime());
            cell = getOrCreateCell(sheetAt, rownum, 7);
            cell.setCellValue(outerDesignChangesDetail.getSource());
            cell = getOrCreateCell(sheetAt, rownum, 8);
            cell.setCellValue(outerDesignChangesDetail.getType());
            cell = getOrCreateCell(sheetAt, rownum, 9);
            cell.setCellValue(outerDesignChangesDetail.getSupplier());
            cell = getOrCreateCell(sheetAt, rownum, 10);
            cell.setCellValue(outerDesignChangesDetail.getTotalFee());
            cell = getOrCreateCell(sheetAt, rownum, 11);
            cell.setCellValue(outerDesignChangesDetail.getOuterDesignChangePrice());
            cell = getOrCreateCell(sheetAt, rownum, 12);
            cell.setCellValue(outerDesignChangesDetail.getInnerDesignChangePrice());
            cell = getOrCreateCell(sheetAt, rownum, 13);
            cell.setCellValue(outerDesignChangesDetail.getMoldPrice());
            cell = getOrCreateCell(sheetAt, rownum, 14);
            cell.setCellValue(outerDesignChangesDetail.getDesignChangeRatio());
//            cell = getOrCreateCell(sheetAt, rownum, 15);
//            cell.setCellValue(outerDesignChangesDetail.getInnerMoldId());
            //详情页
            //保存设变报价单
            sheetAt = sheets.getSheetAt(i + 1);
            sheetAt.getRow(1).getCell(1).setCellValue(outerDesignChangesDetail.getProjectName());
            sheetAt.getRow(1).getCell(9).setCellValue(outerDesignChangesDetail.getMoldName());
            sheetAt.getRow(2).getCell(1).setCellValue(outerDesignChangesDetail.getProductName());
            sheetAt.getRow(2).getCell(9).setCellValue(outerDesignChangesDetail.getMoldId());
            sheetAt.getRow(3).getCell(1).setCellValue(outerDesignChangesDetail.getChangedPeriod());
            sheetAt.getRow(3).getCell(1).setCellValue(outerDesignChangesDetail.getDesignChangesCode());
            sheetAt.getRow(3).getCell(9).setCellValue(outerDesignChangesDetail.getMoldLength());
            sheetAt.getRow(3).getCell(10).setCellValue(outerDesignChangesDetail.getMoldWidth());
            sheetAt.getRow(3).getCell(11).setCellValue(outerDesignChangesDetail.getMoldHeight());
            sheetAt.getRow(4).getCell(1).setCellValue(outerDesignChangesDetail.getChangedPeriod());
            sheetAt.getRow(4).getCell(9).setCellValue(outerDesignChangesDetail.getPress());
            sheetAt.getRow(5).getCell(1).setCellValue(outerDesignChangesDetail.getContent());
            sheetAt.getRow(6).getCell(1).setCellValue(outerDesignChangesDetail.getRectificationPlan());
            sheetAt.getRow(9).getCell(9).setCellValue(outerDesignChangesDetail.getDesignFeeTotal());
            sheetAt.getRow(12).getCell(9).setCellValue(outerDesignChangesDetail.getMachiningFeeTotal());
            sheetAt.getRow(21).getCell(9).setCellValue(outerDesignChangesDetail.getTestFeeTotal());
            sheetAt.getRow(22).getCell(9).setCellValue(outerDesignChangesDetail.getTryoutFeeTotal());
            sheetAt.getRow(23).getCell(9).setCellValue(outerDesignChangesDetail.getTransportFeeTotal());
            sheetAt.getRow(25).getCell(11).setCellValue(outerDesignChangesDetail.getMainFeeCheck());
            sheetAt.getRow(26).getCell(9).setCellValue(outerDesignChangesDetail.getMaterialFeeTotal());
            sheetAt.getRow(31).getCell(11).setCellValue(outerDesignChangesDetail.getMaterialFeeCheck());
            sheetAt.getRow(32).getCell(9).setCellValue(outerDesignChangesDetail.getOtherFeeTotal());
            sheetAt.getRow(35).getCell(1).setCellValue(outerDesignChangesDetail.getSupplier());
            sheetAt.getRow(35).getCell(4).setCellValue(outerDesignChangesDetail.getBidder());
            sheetAt.getRow(35).getCell(7).setCellValue(outerDesignChangesDetail.getTime());
            sheetAt.getRow(35).getCell(9).setCellValue(outerDesignChangesDetail.getTotalFee());
            sheetAt.getRow(35).getCell(11).setCellValue(outerDesignChangesDetail.getTotalFeeCheck());
            sheetAt.getRow(36).getCell(1).setCellValue(outerDesignChangesDetail.getMaker());
            sheetAt.getRow(36).getCell(4).setCellValue(outerDesignChangesDetail.getAuditor());
            sheetAt.getRow(36).getCell(8).setCellValue(outerDesignChangesDetail.getApprover());
            //保存设变报价单每行
            List<OuterDesignChangePrice> outerDesignChangePriceList = outerDesignChangePriceMapper
                    .selectList(new LambdaQueryWrapper<OuterDesignChangePrice>()
                            .eq(OuterDesignChangePrice::getDesignChangeId, outerDesignChangesDetail.getId())
                            .eq(OuterDesignChangePrice::getMoldSelectionId, outerDesignChangesDetail.getMoldSelectionId()));
            outCycle:
            for (OuterDesignChangePrice outerDesignChangePrice : outerDesignChangePriceList) {
                String itemName = outerDesignChangePrice.getName();
                if (outerDesignChangePrice.getType().equals("试模费用")) {
                    sheetAt.getRow(22).getCell(1).setCellValue(outerDesignChangePrice.getName());
                    sheetAt.getRow(22).getCell(3).setCellValue(outerDesignChangePrice.getPrice());
                    sheetAt.getRow(22).getCell(4).setCellValue(outerDesignChangePrice.getNum());
                    sheetAt.getRow(22).getCell(8).setCellValue(outerDesignChangePrice.getTotalPrice());
                }
                //保存主要费用每一行数据
                for (int j = 9; j < 25; j++) {
                    row = sheetAt.getRow(j);
                    if (j != 22) {
                        if (row.getCell(1).getStringCellValue().equals(itemName)) {
                            row.getCell(3).setCellValue(outerDesignChangePrice.getPrice());
                            row.getCell(4).setCellValue(outerDesignChangePrice.getNum());
                            row.getCell(8).setCellValue(outerDesignChangePrice.getTotalPrice());
                            row.getCell(11).setCellValue(outerDesignChangePrice.getCheckPrice());
                            continue outCycle;
                        }
                    }
                }
                for (int j = 26; j < 31; j++) {
                    row = sheetAt.getRow(j);
                    if (row.getCell(1).getStringCellValue().equals(itemName)) {
                        row.getCell(2).setCellValue(outerDesignChangePrice.getSpecification());
                        row.getCell(3).setCellValue(outerDesignChangePrice.getPrice());
                        row.getCell(4).setCellValue(outerDesignChangePrice.getLength());
                        row.getCell(5).setCellValue(outerDesignChangePrice.getWidth());
                        row.getCell(6).setCellValue(outerDesignChangePrice.getHeight());
                        row.getCell(7).setCellValue(outerDesignChangePrice.getNum());
                        row.getCell(8).setCellValue(outerDesignChangePrice.getTotalPrice());
                        row.getCell(11).setCellValue(outerDesignChangePrice.getCheckPrice());
                        continue outCycle;
                    }
                }
                for (int j = 32; j < 35; j++) {
                    row = sheetAt.getRow(j);
                    if (row.getCell(1).getStringCellValue().equals(itemName)) {
                        row.getCell(2).setCellValue(outerDesignChangePrice.getNum());
                        row.getCell(3).setCellValue(outerDesignChangePrice.getTotalPrice());
                        row.getCell(11).setCellValue(outerDesignChangePrice.getCheckPrice());
                        continue outCycle;
                    }
                }
            }
        }
        sheetAt = sheets.getSheetAt(0);
        //详情数据数量小于3时按照3行详情表排格式
        if (detailNum < 3) {
            detailNum = 3;
        }
        row = sheetAt.getRow(10 + detailNum);
        row.getCell(10).setCellValue(outerDesignChanges.getSupplierFeeTotal());
        row.getCell(11).setCellValue(outerDesignChanges.getOuterDesignChangePrice());
        row.getCell(12).setCellValue(outerDesignChanges.getInnerDesignChangePrice());
        row = sheetAt.getRow(13 + detailNum);
        row.getCell(0).setCellValue(outerDesignChanges.getMoldTotalPrice());
        row.getCell(5).setCellValue(outerDesignChanges.getOuterDesignChangePrice());
        row.getCell(7).setCellValue(outerDesignChanges.getInnerDesignChangePrice());
        row.getCell(9).setCellValue(outerDesignChanges.getOuterDesignChangeRatio());
        row.getCell(12).setCellValue(outerDesignChanges.getInnerDesignChangeRatio());
        row = sheetAt.getRow(14 + detailNum);
        row.getCell(5).setCellValue(MyUtils.formatDouble(outerDesignChanges.getOuterDesignChangePrice()) + MyUtils.formatDouble(outerDesignChanges.getInnerDesignChangePrice()));
        row.getCell(9).setCellValue(MyUtils.formatDouble(outerDesignChanges.getOuterDesignChangeRatio()) + MyUtils.formatDouble(outerDesignChanges.getInnerDesignChangeRatio()));
        row = sheetAt.getRow(18 + detailNum);
        row.getCell(3).setCellValue(outerDesignChanges.getControlRoomDirector());
        row.getCell(5).setCellValue(outerDesignChanges.getManager());
        row.getCell(6).setCellValue(outerDesignChanges.getLeader());
        row.getCell(9).setCellValue(outerDesignChanges.getMinister());
        row = sheetAt.getRow(16 + detailNum);
        row.getCell(0).setCellValue("拟制： " + outerDesignChanges.getMaker());
        row.getCell(12).setCellValue("批准： " + outerDesignChanges.getApprover());
    }

    private BigDecimal getMainFeeCheck(JSONObject jsonObjectdetail) {
        JSONObject jsonObjectTransportFee = jsonObjectdetail.getJSONObject("transportFeeObject");
        JSONObject jsonObjectTryoutFee = jsonObjectdetail.getJSONObject("tryoutFeeObject");
        JSONObject jsonObjectTestFee = jsonObjectdetail.getJSONObject("measureFeeObject");
        JSONObject jsonObjectMachiningFee = jsonObjectdetail.getJSONObject("processFeeObject");
        JSONObject jsonObjectDesignFee = jsonObjectdetail.getJSONObject("designFeeObject");
        JSONArray transportFeeDataList = jsonObjectTransportFee.getJSONArray("dataList");
        JSONArray tryoutFeeDataList = jsonObjectTryoutFee.getJSONArray("dataList");
        JSONArray testFeeDataList = jsonObjectTestFee.getJSONArray("dataList");
        JSONArray processFeeDataList = jsonObjectMachiningFee.getJSONArray("dataList");
        JSONArray designFeeDataList = jsonObjectDesignFee.getJSONArray("dataList");
        BigDecimal mainFeeCheck = getFeeCheck(transportFeeDataList).add(getFeeCheck(tryoutFeeDataList))
                .add(getFeeCheck(testFeeDataList)).add(getFeeCheck(processFeeDataList)).add(getFeeCheck(designFeeDataList));
        return mainFeeCheck;
    }

    private BigDecimal getFeeCheck(JSONArray jsonArrayList) {
        BigDecimal feeCheck = new BigDecimal("0");
        for (int j = 0; j < jsonArrayList.size(); j++) {
            JSONObject jsonObject = jsonArrayList.getJSONObject(j);
            feeCheck = feeCheck.add(BigdecimalUtil.stringToBigDecimal(jsonObject.getString("checkPrice")));
        }
        return feeCheck;
    }

    private boolean savePrice(JSONArray dataList, String type, String moldSelectionId, String subTableId, String subTotal) throws RuntimeException {
        BigDecimal subTotalSum = new BigDecimal("0");
        for (int j = 0; j < dataList.size(); j++) {
            JSONObject feeData = dataList.getJSONObject(j);
            OuterDesignChangePrice outerDesignChangePrice = new OuterDesignChangePrice();
            String itemName = feeData.getString("itemName");
            String id = feeData.getString("id");
            if (StringUtils.isNotEmpty(id)) {
                outerDesignChangePrice.setId(id);
            }
            outerDesignChangePrice.setMoldSelectionId(moldSelectionId);
            outerDesignChangePrice.setDesignChangeId(subTableId);
            outerDesignChangePrice.setType(type);
            outerDesignChangePrice.setName(itemName);
            outerDesignChangePrice.setPrice(BigdecimalUtil.stringTo2DecimalString(feeData.getString("price")));
            outerDesignChangePrice.setTotalPrice(BigdecimalUtil.stringTo2DecimalString(feeData.getString("totalPrice")));
            outerDesignChangePrice.setCheckPrice(BigdecimalUtil.stringTo2DecimalString(feeData.getString("checkPrice")));

            BigDecimal totalPrice = BigdecimalUtil.double2BigDecimal2Decimal(feeData.getDoubleValue("totalPrice")).setScale(2, RoundingMode.HALF_UP);
            if (type.equals("材料费用")) {
                double num = feeData.getDoubleValue("weight");
                double lengthOfspecification = feeData.getDoubleValue("lengthOfspecification");
                double widthOfspecification = feeData.getDoubleValue("widthOfspecification");
                double heightOfspecification = feeData.getDoubleValue("heightOfspecification");
                BigDecimal length = BigdecimalUtil.double2BigDecimal2Decimal(lengthOfspecification);
                BigDecimal width = BigdecimalUtil.double2BigDecimal2Decimal(widthOfspecification);
                BigDecimal height = BigdecimalUtil.double2BigDecimal2Decimal(heightOfspecification);
                outerDesignChangePrice.setNum(BigdecimalUtil.doubleTo3DecimalString(num));
                outerDesignChangePrice.setLength(BigdecimalUtil.doubleTo2DecimalString(lengthOfspecification));
                outerDesignChangePrice.setWidth(BigdecimalUtil.doubleTo2DecimalString(widthOfspecification));
                outerDesignChangePrice.setHeight(BigdecimalUtil.doubleTo2DecimalString(heightOfspecification));
                outerDesignChangePrice.setSpecification(feeData.getString("brand"));

                double weightResult = length.multiply(width).multiply(height).multiply(new BigDecimal("0.00000785")).setScale(3, RoundingMode.HALF_UP).doubleValue();
                if (weightResult != num) {
                    throw new RuntimeException(type + "-" + itemName + "重量计算结果不一致。结果为" + weightResult);
                }

                BigDecimal price = BigdecimalUtil.double2BigDecimal2Decimal(feeData.getDoubleValue("price"));
                BigDecimal weight = BigdecimalUtil.double2BigDecimal3Decimal(num);
                BigDecimal totalPriceBig = price.multiply(weight).setScale(2, RoundingMode.HALF_UP);

                if (totalPriceBig.compareTo(totalPrice) != 0) {
                    throw new RuntimeException(type + "-" + itemName + "金额计算结果不一致。结果为" + totalPriceBig.doubleValue());
                }
            } else {
                outerDesignChangePrice.setNum(BigdecimalUtil.stringTo2DecimalString(feeData.getString("hour")));

                BigDecimal price = BigdecimalUtil.double2BigDecimal2Decimal(feeData.getDoubleValue("price"));
                BigDecimal hour = BigdecimalUtil.double2BigDecimal2Decimal(feeData.getDoubleValue("hour"));

                BigDecimal totalPriceBig = price.multiply(hour).setScale(2, RoundingMode.HALF_UP);
                if (totalPriceBig.compareTo(totalPrice) != 0) {
                    throw new RuntimeException(type + "-" + itemName + "金额计算结果不一致。结果为" + totalPriceBig.doubleValue());
                }
            }
            subTotalSum = subTotalSum.add(totalPrice);
            boolean bOuterDesignChangePrice = iOuterDesignChangePriceService
                    //id相同或分表id且类型名称相同则更新
                    .saveOrUpdate(outerDesignChangePrice, new LambdaUpdateWrapper<OuterDesignChangePrice>()
                            .eq(OuterDesignChangePrice::getId, id)
                            .or()
                            .eq(OuterDesignChangePrice::getDesignChangeId, subTableId)
                            .eq(OuterDesignChangePrice::getType, type)
                            .eq(OuterDesignChangePrice::getName, itemName));
            if (!bOuterDesignChangePrice) {
                return false;
            }
        }
        if (subTotalSum.compareTo(BigdecimalUtil.stringToBigDecimal(subTotal)) != 0) {
            throw new RuntimeException(type + "-小计计算结果不一致。结果为" + subTotalSum);
        }
        return true;
    }

    private boolean savePriceOtherFee(JSONArray dataList, String type, String moldSelectionId, String subTableId, String subTotal, BigDecimal subTotalTotal) throws RuntimeException {
        BigDecimal subTotalSum = new BigDecimal("0");
        BigDecimal managementFee = new BigDecimal("0");
        BigDecimal profit = new BigDecimal("0");
        BigDecimal taxTotalPrice = new BigDecimal(0);
        BigDecimal taxCount = new BigDecimal(0);
        //是否校验税收
        boolean flag = false;

        for (int j = 0; j < dataList.size(); j++) {
            JSONObject feeData = dataList.getJSONObject(j);
            OuterDesignChangePrice outerDesignChangePrice = new OuterDesignChangePrice();
            String itemName = feeData.getString("itemName");
            String id = feeData.getString("id");
            if (StringUtils.isNotEmpty(id)) {
                outerDesignChangePrice.setId(id);
            }
            outerDesignChangePrice.setMoldSelectionId(moldSelectionId);
            outerDesignChangePrice.setDesignChangeId(subTableId);
            outerDesignChangePrice.setType(type);
            outerDesignChangePrice.setName(itemName);
            outerDesignChangePrice.setTotalPrice(BigdecimalUtil.stringTo2DecimalString(feeData.getString("totalPrice")));
            outerDesignChangePrice.setCheckPrice(BigdecimalUtil.stringTo2DecimalString(feeData.getString("checkPrice")));
            outerDesignChangePrice.setNum(BigdecimalUtil.stringTo2DecimalString(feeData.getString("ratio")));

            BigDecimal totalPrice = BigdecimalUtil.double2BigDecimal2Decimal(feeData.getDoubleValue("totalPrice")).setScale(2, RoundingMode.HALF_UP);
            BigDecimal count = BigdecimalUtil.double2BigDecimal2Decimal(feeData.getDoubleValue("ratio")).divide(new BigDecimal("100"));
            if ("管理费".equals(itemName)) {
                managementFee = managementFee.add(totalPrice);
                BigDecimal totalPriceBig = subTotalTotal.multiply(count).setScale(2, RoundingMode.HALF_UP);
                if (totalPriceBig.compareTo(totalPrice) != 0) {
                    throw new RuntimeException(type + "-" + itemName + "金额计算结果不一致。结果为" + totalPriceBig.doubleValue());
                }
            } else if ("利润".equals(itemName)) {
                profit = profit.add(totalPrice);
                BigDecimal totalPriceBig = subTotalTotal.multiply(count).setScale(2, RoundingMode.HALF_UP);
                if (totalPriceBig.compareTo(totalPrice) != 0) {
                    throw new RuntimeException(type + "-" + itemName + "金额计算结果不一致。结果为" + totalPriceBig.doubleValue());
                }
            } else if ("税收".equals(itemName)) {
                taxCount = count;
                taxTotalPrice = totalPrice;
                flag = true;
            }

            subTotalSum = subTotalSum.add(totalPrice);
            boolean bOuterDesignChangePrice = iOuterDesignChangePriceService
                    //id相同或分表id且类型名称相同则更新
                    .saveOrUpdate(outerDesignChangePrice, new LambdaUpdateWrapper<OuterDesignChangePrice>()
                            .eq(OuterDesignChangePrice::getId, id)
                            .or()
                            .eq(OuterDesignChangePrice::getDesignChangeId, subTableId)
                            .eq(OuterDesignChangePrice::getType, type)
                            .eq(OuterDesignChangePrice::getName, itemName));
            if (!bOuterDesignChangePrice) {
                return false;
            }
        }

        if (flag) {
            BigDecimal add = subTotalTotal.add(managementFee).add(profit);
            BigDecimal totalPriceBig = add.multiply(taxCount).setScale(2, RoundingMode.HALF_UP);
            if (totalPriceBig.compareTo(taxTotalPrice) != 0) {
                throw new RuntimeException(type + "-税收金额计算结果不一致。结果为" + totalPriceBig.doubleValue());
            }
        }

        if (subTotalSum.compareTo(BigdecimalUtil.stringToBigDecimal(subTotal)) != 0) {
            throw new RuntimeException(type + "-小计计算结果不一致。结果为" + subTotalSum);
        }
        return true;
    }

    /**
     * 创建行
     */
    private void createOuterRow(XSSFSheet sheet, int startRow, int createRow) {
        sheet.shiftRows(13, 21, createRow, true, false);
        for (int i = 0; i < createRow; i++) {
            sheet.copyRows(12, 12, 13 + i, new CellCopyPolicy());
            sheet.getRow(13 + i).getCell(0).setCellValue(Integer.toString(4 + i));
            sheet.getRow(13 + i).setHeightInPoints((short) -1);
        }
    }

    /**
     * 获取cell，为null则创建
     *
     * @param sheet
     * @param rowIndex
     * @param colIndex
     * @return
     */
    private static XSSFCell getOrCreateCell(XSSFSheet sheet, int rowIndex, int colIndex) {
        XSSFRow row = sheet.getRow(rowIndex);
        if (row == null) {
            row = sheet.createRow(rowIndex);
        }
        XSSFCell cell = row.getCell(colIndex);
        if (cell == null) {
            cell = row.createCell(colIndex);
        }
        return cell;
    }

    private void exportInnerDesignChangeDetailExcel(XSSFWorkbook workbook, XSSFSheet sheet, InnerDesignChangesDetail innerDesignChangesDetail) {
        //列宽
        sheet.setColumnWidth(0, 10 * 256);
        sheet.setColumnWidth(1, 8 * 256);
        sheet.setColumnWidth(2, 8 * 256);
        sheet.setColumnWidth(3, 10 * 256);
        sheet.setColumnWidth(4, 8 * 256);
        sheet.setColumnWidth(5, 8 * 256);
        sheet.setColumnWidth(6, 8 * 256);
        sheet.setColumnWidth(7, 8 * 256);
        sheet.setColumnWidth(8, 10 * 256);
        sheet.setColumnWidth(9, 5 * 256);
        sheet.setColumnWidth(10, 5 * 256);
        sheet.setColumnWidth(11, 8 * 256);

        CellRangeAddress cellRangeAddress0 = new CellRangeAddress(0, 0, 0, 11);
        ExcelUtil.setCellRangeBorderThin(sheet, cellRangeAddress0);
        sheet.addMergedRegion(cellRangeAddress0);
        XSSFCellStyle cellStyle0 = workbook.createCellStyle();
        cellStyle0.setAlignment(HorizontalAlignment.CENTER);
        cellStyle0.setVerticalAlignment(VerticalAlignment.CENTER);
        cellStyle0.setBorderBottom(BorderStyle.THIN);
        cellStyle0.setBorderLeft(BorderStyle.THIN);
        cellStyle0.setBorderTop(BorderStyle.THIN);
        cellStyle0.setBorderRight(BorderStyle.THIN);
        XSSFFont font0 = workbook.createFont();
        font0.setFontName("宋体");
        font0.setFontHeightInPoints((short) 20);
        cellStyle0.setFont(font0);
        Row row0 = ExcelUtil.getRow(sheet, 0);
        row0.setHeightInPoints(36);
        Cell cell0 = ExcelUtil.getCell(row0, 0);
        cell0.setCellStyle(cellStyle0);
        cell0.setCellValue("成都航模模塑股份有限公司模具设变报价单");

        CellRangeAddress cellRangeAddress1_1 = new CellRangeAddress(1, 1, 1, 2);
        ExcelUtil.setCellRangeBorderThin(sheet, cellRangeAddress1_1);
        sheet.addMergedRegion(cellRangeAddress1_1);
        CellRangeAddress cellRangeAddress1_2 = new CellRangeAddress(1, 4, 3, 7);
        ExcelUtil.setCellRangeBorderThin(sheet, cellRangeAddress1_2);
        sheet.addMergedRegion(cellRangeAddress1_2);
        CellRangeAddress cellRangeAddress1_4 = new CellRangeAddress(1, 1, 9, 11);
        ExcelUtil.setCellRangeBorderThin(sheet, cellRangeAddress1_4);
        sheet.addMergedRegion(cellRangeAddress1_4);
        XSSFCellStyle cellStyle1 = workbook.createCellStyle();
        cellStyle1.setAlignment(HorizontalAlignment.CENTER);
        cellStyle1.setVerticalAlignment(VerticalAlignment.CENTER);
        cellStyle1.setWrapText(true);
        cellStyle1.setBorderBottom(BorderStyle.THIN);
        cellStyle1.setBorderLeft(BorderStyle.THIN);
        cellStyle1.setBorderTop(BorderStyle.THIN);
        cellStyle1.setBorderRight(BorderStyle.THIN);
        XSSFFont font1 = workbook.createFont();
        font1.setFontName("宋体");
        font1.setFontHeightInPoints((short) 9);
        cellStyle1.setFont(font1);
        Row row1 = ExcelUtil.getRow(sheet, 1);
        row1.setHeightInPoints(20);
        Cell cell1_0 = ExcelUtil.getCell(row1, 0);
        cell1_0.setCellStyle(cellStyle1);
        cell1_0.setCellValue("项目名称");
        Cell cell1_1 = ExcelUtil.getCell(row1, 1);
        cell1_1.setCellStyle(cellStyle1);
        cell1_1.setCellValue(innerDesignChangesDetail.getProjectName());
        Cell cell1_2 = ExcelUtil.getCell(row1, 3);
        cell1_2.setCellStyle(cellStyle1);
        Cell cell1_3 = ExcelUtil.getCell(row1, 8);
        cell1_3.setCellStyle(cellStyle1);
        cell1_3.setCellValue("模具名称");
        Cell cell1_4 = ExcelUtil.getCell(row1, 9);
        cell1_4.setCellStyle(cellStyle1);
        cell1_4.setCellValue(innerDesignChangesDetail.getMoldName());

        CellRangeAddress cellRangeAddress2_1 = new CellRangeAddress(2, 2, 1, 2);
        ExcelUtil.setCellRangeBorderThin(sheet, cellRangeAddress2_1);
        sheet.addMergedRegion(cellRangeAddress2_1);
        CellRangeAddress cellRangeAddress2_4 = new CellRangeAddress(2, 2, 9, 11);
        ExcelUtil.setCellRangeBorderThin(sheet, cellRangeAddress2_4);
        sheet.addMergedRegion(cellRangeAddress2_4);
        Row row2 = ExcelUtil.getRow(sheet, 2);
        row2.setHeightInPoints(20);
        Cell cell2_0 = ExcelUtil.getCell(row2, 0);
        cell2_0.setCellStyle(cellStyle1);
        cell2_0.setCellValue("产品名称");
        Cell cell2_1 = ExcelUtil.getCell(row2, 1);
        cell2_1.setCellStyle(cellStyle1);
        cell2_1.setCellValue(innerDesignChangesDetail.getProductName());
        Cell cell2_3 = ExcelUtil.getCell(row2, 8);
        cell2_3.setCellStyle(cellStyle1);
        cell2_3.setCellValue("模具编号");
        Cell cell2_4 = ExcelUtil.getCell(row2, 9);
        cell2_4.setCellStyle(cellStyle1);
        cell2_4.setCellValue(innerDesignChangesDetail.getMoldId());

        CellRangeAddress cellRangeAddress3_1 = new CellRangeAddress(3, 3, 1, 2);
        ExcelUtil.setCellRangeBorderThin(sheet, cellRangeAddress3_1);
        sheet.addMergedRegion(cellRangeAddress3_1);
        Row row3 = ExcelUtil.getRow(sheet, 3);
        row3.setHeightInPoints(20);
        Cell cell3_0 = ExcelUtil.getCell(row3, 0);
        cell3_0.setCellStyle(cellStyle1);
        cell3_0.setCellValue("设变单号");
        Cell cell3_1 = ExcelUtil.getCell(row3, 1);
        cell3_1.setCellStyle(cellStyle1);
        cell3_1.setCellValue(innerDesignChangesDetail.getDesignChangesCode());
        Cell cell3_3 = ExcelUtil.getCell(row3, 8);
        cell3_3.setCellStyle(cellStyle1);
        cell3_3.setCellValue("模具外形");
        Cell cell3_4 = ExcelUtil.getCell(row3, 9);
        cell3_4.setCellStyle(cellStyle1);
        cell3_4.setCellValue(innerDesignChangesDetail.getMoldLength());
        Cell cell3_5 = ExcelUtil.getCell(row3, 10);
        cell3_5.setCellStyle(cellStyle1);
        cell3_5.setCellValue(innerDesignChangesDetail.getMoldWidth());
        Cell cell3_6 = ExcelUtil.getCell(row3, 11);
        cell3_6.setCellStyle(cellStyle1);
        cell3_6.setCellValue(innerDesignChangesDetail.getMoldHeight());

        CellRangeAddress cellRangeAddress4_1 = new CellRangeAddress(4, 4, 1, 2);
        ExcelUtil.setCellRangeBorderThin(sheet, cellRangeAddress4_1);
        sheet.addMergedRegion(cellRangeAddress4_1);
        CellRangeAddress cellRangeAddress4_4 = new CellRangeAddress(4, 4, 9, 11);
        ExcelUtil.setCellRangeBorderThin(sheet, cellRangeAddress4_4);
        sheet.addMergedRegion(cellRangeAddress4_4);
        Row row4 = ExcelUtil.getRow(sheet, 4);
        row4.setHeightInPoints(20);
        Cell cell4_0 = ExcelUtil.getCell(row4, 0);
        cell4_0.setCellStyle(cellStyle1);
        cell4_0.setCellValue("设变周期");
        Cell cell4_1 = ExcelUtil.getCell(row4, 1);
        cell4_1.setCellStyle(cellStyle1);
        cell4_1.setCellValue(innerDesignChangesDetail.getChangedPeriod());
        Cell cell4_3 = ExcelUtil.getCell(row4, 8);
        cell4_3.setCellStyle(cellStyle1);
        cell4_3.setCellValue("定义机台");
        Cell cell4_4 = ExcelUtil.getCell(row4, 9);
        cell4_4.setCellStyle(cellStyle1);
        cell4_4.setCellValue(innerDesignChangesDetail.getPress());

        CellRangeAddress cellRangeAddress5_1 = new CellRangeAddress(5, 5, 1, 11);
        ExcelUtil.setCellRangeBorderThin(sheet, cellRangeAddress5_1);
        sheet.addMergedRegion(cellRangeAddress5_1);
        Row row5 = ExcelUtil.getRow(sheet, 5);
        row5.setHeightInPoints(60);
        Cell cell5_0 = ExcelUtil.getCell(row5, 0);
        cell5_0.setCellStyle(cellStyle1);
        cell5_0.setCellValue("设变内容");
        Cell cell5_1 = ExcelUtil.getCell(row5, 1);
        cell5_1.setCellStyle(cellStyle1);
        cell5_1.setCellValue(innerDesignChangesDetail.getContent());

        CellRangeAddress cellRangeAddress6_1 = new CellRangeAddress(6, 6, 1, 11);
        ExcelUtil.setCellRangeBorderThin(sheet, cellRangeAddress6_1);
        sheet.addMergedRegion(cellRangeAddress6_1);
        Row row6 = ExcelUtil.getRow(sheet, 6);
        row6.setHeightInPoints(60);
        Cell cell6_0 = ExcelUtil.getCell(row6, 0);
        cell6_0.setCellStyle(cellStyle1);
        cell6_0.setCellValue("整改方案");
        Cell cell6_1 = ExcelUtil.getCell(row6, 1);
        cell6_1.setCellStyle(cellStyle1);
        cell6_1.setCellValue(innerDesignChangesDetail.getRectificationPlan());

        CellRangeAddress cellRangeAddress7_0 = new CellRangeAddress(7, 7, 0, 10);
        ExcelUtil.setCellRangeBorderThin(sheet, cellRangeAddress7_0);
        sheet.addMergedRegion(cellRangeAddress7_0);
        CellRangeAddress cellRangeAddress7_1 = new CellRangeAddress(7, 8, 11, 11);
        ExcelUtil.setCellRangeBorderThin(sheet, cellRangeAddress7_1);
        sheet.addMergedRegion(cellRangeAddress7_1);
        Row row7 = ExcelUtil.getRow(sheet, 7);
        row7.setHeightInPoints(20);
        Cell cell7_0 = ExcelUtil.getCell(row7, 0);
        cell7_0.setCellStyle(cellStyle1);
        cell7_0.setCellValue("报价明细");
        Cell cell7_1 = ExcelUtil.getCell(row7, 11);
        cell7_1.setCellStyle(cellStyle1);
        cell7_1.setCellValue("核价明细");

        CellRangeAddress cellRangeAddress8_1 = new CellRangeAddress(8, 8, 1, 2);
        ExcelUtil.setCellRangeBorderThin(sheet, cellRangeAddress8_1);
        sheet.addMergedRegion(cellRangeAddress8_1);
        CellRangeAddress cellRangeAddress8_3 = new CellRangeAddress(8, 8, 4, 7);
        ExcelUtil.setCellRangeBorderThin(sheet, cellRangeAddress8_3);
        sheet.addMergedRegion(cellRangeAddress8_3);
        CellRangeAddress cellRangeAddress8_5 = new CellRangeAddress(8, 8, 9, 10);
        ExcelUtil.setCellRangeBorderThin(sheet, cellRangeAddress8_5);
        sheet.addMergedRegion(cellRangeAddress8_5);
        Row row8 = ExcelUtil.getRow(sheet, 8);
        row8.setHeightInPoints(20);
        Cell cell8_0 = ExcelUtil.getCell(row8, 0);
        cell8_0.setCellStyle(cellStyle1);
        cell8_0.setCellValue("科目");
        Cell cell8_1 = ExcelUtil.getCell(row8, 1);
        cell8_1.setCellStyle(cellStyle1);
        cell8_1.setCellValue("项目");
        Cell cell8_2 = ExcelUtil.getCell(row8, 3);
        cell8_2.setCellStyle(cellStyle1);
        cell8_2.setCellValue("单价（元）");
        Cell cell8_3 = ExcelUtil.getCell(row8, 4);
        cell8_3.setCellStyle(cellStyle1);
        cell8_3.setCellValue("工时h/里程km");
        Cell cell8_4 = ExcelUtil.getCell(row8, 8);
        cell8_4.setCellStyle(cellStyle1);
        cell8_4.setCellValue("金额（元）");
        Cell cell8_5 = ExcelUtil.getCell(row8, 9);
        cell8_5.setCellStyle(cellStyle1);

        int rowNum = 9;
        List<InnerDesignChangePrice> outerDesignChangePrices = priceService.list(new LambdaQueryWrapper<InnerDesignChangePrice>()
                .eq(InnerDesignChangePrice::getMoldSelectionId, innerDesignChangesDetail.getMoldSelectionId())
                .eq(InnerDesignChangePrice::getDesignChangeId, innerDesignChangesDetail.getId()));
        Map<String, List<InnerDesignChangePrice>> typeMap = outerDesignChangePrices.stream().collect(Collectors.groupingBy(InnerDesignChangePrice::getType));
        rowNum = exportInnerDesignChangePriceExcel(sheet, cellStyle1, rowNum, typeMap, "设计费用", innerDesignChangesDetail.getDesignFeeTotal());
        rowNum = exportInnerDesignChangePriceExcel(sheet, cellStyle1, rowNum, typeMap, "加工费用", innerDesignChangesDetail.getMachiningFeeTotal());
        rowNum = exportInnerDesignChangePriceExcel(sheet, cellStyle1, rowNum, typeMap, "检测费用", innerDesignChangesDetail.getTestFeeTotal());
        rowNum = exportInnerDesignChangePriceExcel(sheet, cellStyle1, rowNum, typeMap, "试模费用", innerDesignChangesDetail.getTryoutFeeTotal());
        rowNum = exportInnerDesignChangePriceExcel(sheet, cellStyle1, rowNum, typeMap, "运输费用", innerDesignChangesDetail.getTransportFeeTotal());
        rowNum = exportInnerDesignChangePriceExcel2(sheet, cellStyle1, rowNum, typeMap, "材料费用", innerDesignChangesDetail);
        rowNum = exportInnerDesignChangePriceExcel3(sheet, cellStyle1, rowNum, typeMap, "其它费用", innerDesignChangesDetail);

        CellRangeAddress cellRangeAddress99_2 = new CellRangeAddress(rowNum, rowNum, 2, 3);
        ExcelUtil.setCellRangeBorderThin(sheet, cellRangeAddress99_2);
        sheet.addMergedRegion(cellRangeAddress99_2);
        CellRangeAddress cellRangeAddress99_4 = new CellRangeAddress(rowNum, rowNum, 5, 6);
        ExcelUtil.setCellRangeBorderThin(sheet, cellRangeAddress99_4);
        sheet.addMergedRegion(cellRangeAddress99_4);
        CellRangeAddress cellRangeAddress99_7 = new CellRangeAddress(rowNum, rowNum, 9, 10);
        ExcelUtil.setCellRangeBorderThin(sheet, cellRangeAddress99_7);
        sheet.addMergedRegion(cellRangeAddress99_7);
        Row row99 = ExcelUtil.getRow(sheet, rowNum);
        row99.setHeightInPoints(36);
        Cell cell99_0 = ExcelUtil.getCell(row99, 0);
        cell99_0.setCellStyle(cellStyle1);
        cell99_0.setCellValue("供应商：");
        Cell cell99_1 = ExcelUtil.getCell(row99, 1);
        cell99_1.setCellStyle(cellStyle1);
        final String supplier = innerDesignChangesDetail.getSupplier();
        if (StringUtils.isNotEmpty(supplier)) {
            final DictTable dictTable = dictTableMapper.selectOne(new LambdaQueryWrapper<DictTable>().eq(DictTable::getDicId, supplier));
            if (ObjectUtil.isNotEmpty(dictTable)) {
                cell99_1.setCellValue(dictTable.getDicName());
            }
        }
        Cell cell99_2 = ExcelUtil.getCell(row99, 2);
        cell99_2.setCellStyle(cellStyle1);
        cell99_2.setCellValue("供应商报价人签字：");
        Cell cell99_3 = ExcelUtil.getCell(row99, 4);
        cell99_3.setCellStyle(cellStyle1);
        cell99_3.setCellValue(innerDesignChangesDetail.getBidder());
        Cell cell99_4 = ExcelUtil.getCell(row99, 5);
        cell99_4.setCellStyle(cellStyle1);
        cell99_4.setCellValue("时间：");
        Cell cell99_5 = ExcelUtil.getCell(row99, 7);
        cell99_5.setCellStyle(cellStyle1);
        cell99_5.setCellValue(innerDesignChangesDetail.getTime());
        Cell cell99_6 = ExcelUtil.getCell(row99, 8);
        cell99_6.setCellStyle(cellStyle1);
        cell99_6.setCellValue("合计：");
        Cell cell99_7 = ExcelUtil.getCell(row99, 9);
        cell99_7.setCellStyle(cellStyle1);
        cell99_7.setCellValue(innerDesignChangesDetail.getTotalFee());
        Cell cell99_8 = ExcelUtil.getCell(row99, 11);
        cell99_8.setCellStyle(cellStyle1);
        cell99_8.setCellValue(innerDesignChangesDetail.getTotalFeeCheck());
        rowNum++;

        XSSFCellStyle cellStyle100 = workbook.createCellStyle();
        cellStyle100.setAlignment(HorizontalAlignment.LEFT);
        cellStyle100.setVerticalAlignment(VerticalAlignment.CENTER);
        cellStyle100.setWrapText(true);
        cellStyle100.setBorderBottom(BorderStyle.THIN);
        cellStyle100.setBorderLeft(BorderStyle.THIN);
        cellStyle100.setBorderTop(BorderStyle.THIN);
        cellStyle100.setBorderRight(BorderStyle.THIN);
        XSSFFont font100 = workbook.createFont();
        font100.setBold(true);
        font100.setFontName("宋体");
        font100.setFontHeightInPoints((short) 9);
        cellStyle100.setFont(font100);
        CellRangeAddress cellRangeAddress100_0 = new CellRangeAddress(rowNum, rowNum, 0, 2);
        ExcelUtil.setCellRangeBorderThin(sheet, cellRangeAddress100_0);
        sheet.addMergedRegion(cellRangeAddress100_0);
        CellRangeAddress cellRangeAddress100_1 = new CellRangeAddress(rowNum, rowNum, 3, 6);
        ExcelUtil.setCellRangeBorderThin(sheet, cellRangeAddress100_1);
        sheet.addMergedRegion(cellRangeAddress100_1);
        CellRangeAddress cellRangeAddress100_2 = new CellRangeAddress(rowNum, rowNum, 7, 11);
        ExcelUtil.setCellRangeBorderThin(sheet, cellRangeAddress100_2);
        sheet.addMergedRegion(cellRangeAddress100_2);
        Row row100 = ExcelUtil.getRow(sheet, rowNum);
        row100.setHeightInPoints(36);
        Cell cell100_0 = ExcelUtil.getCell(row100, 0);
        cell100_0.setCellStyle(cellStyle100);
        String maker = innerDesignChangesDetail.getMaker();
        cell100_0.setCellValue("拟制：" + (StringUtils.isEmpty(maker) ? "" : maker));
        Cell cell100_1 = ExcelUtil.getCell(row100, 3);
        cell100_1.setCellStyle(cellStyle100);
        String auditor = innerDesignChangesDetail.getAuditor();
        cell100_1.setCellValue("审核：" + (StringUtils.isEmpty(auditor) ? "" : auditor));
        Cell cell100_2 = ExcelUtil.getCell(row100, 7);
        cell100_2.setCellStyle(cellStyle100);
        String approver = innerDesignChangesDetail.getApprover();
        cell100_2.setCellValue("批准：" + (StringUtils.isEmpty(approver) ? "" : approver));
    }

    private int exportInnerDesignChangePriceExcel(XSSFSheet sheet, XSSFCellStyle xssfCellStyle, int rowNum, Map<String, List<InnerDesignChangePrice>> typeMap, String type, String designFeeTotal) {
        if (typeMap.containsKey(type)) {
            List<InnerDesignChangePrice> outerDesignChangePricesList = typeMap.get(type);
            int size = outerDesignChangePricesList.size();
            if (size > 1) {
                CellRangeAddress typeCellRangeAddress = new CellRangeAddress(rowNum, rowNum + size - 1, 0, 0);
                ExcelUtil.setCellRangeBorderThin(sheet, typeCellRangeAddress);
                sheet.addMergedRegion(typeCellRangeAddress);
                CellRangeAddress subtotalCellRangeAddress = new CellRangeAddress(rowNum, rowNum + size - 1, 9, 10);
                ExcelUtil.setCellRangeBorderThin(sheet, subtotalCellRangeAddress);
                sheet.addMergedRegion(subtotalCellRangeAddress);
                Row firstRow = ExcelUtil.getRow(sheet, rowNum);
                Cell cell_0 = ExcelUtil.getCell(firstRow, 0);
                cell_0.setCellStyle(xssfCellStyle);
                cell_0.setCellValue(type);
                Cell cell_5 = ExcelUtil.getCell(firstRow, 9);
                cell_5.setCellStyle(xssfCellStyle);
                cell_5.setCellValue(designFeeTotal);
                for (int i = 0; i < size; i++) {
                    CellRangeAddress cellRangeAddress_1 = new CellRangeAddress(rowNum, rowNum, 1, 2);
                    ExcelUtil.setCellRangeBorderThin(sheet, cellRangeAddress_1);
                    sheet.addMergedRegion(cellRangeAddress_1);
                    CellRangeAddress cellRangeAddress_3 = new CellRangeAddress(rowNum, rowNum, 4, 7);
                    ExcelUtil.setCellRangeBorderThin(sheet, cellRangeAddress_3);
                    sheet.addMergedRegion(cellRangeAddress_3);
                    Row row = ExcelUtil.getRow(sheet, rowNum);
                    row.setHeightInPoints(20);
                    InnerDesignChangePrice outerDesignChangePrice = outerDesignChangePricesList.get(i);
                    Cell cell_1 = ExcelUtil.getCell(row, 1);
                    cell_1.setCellStyle(xssfCellStyle);
                    cell_1.setCellValue(outerDesignChangePrice.getName());
                    Cell cell_2 = ExcelUtil.getCell(row, 3);
                    cell_2.setCellStyle(xssfCellStyle);
                    cell_2.setCellValue(outerDesignChangePrice.getPrice());
                    Cell cell_3 = ExcelUtil.getCell(row, 4);
                    cell_3.setCellStyle(xssfCellStyle);
                    cell_3.setCellValue(outerDesignChangePrice.getNum());
                    Cell cell_4 = ExcelUtil.getCell(row, 8);
                    cell_4.setCellStyle(xssfCellStyle);
                    cell_4.setCellValue(outerDesignChangePrice.getTotalPrice());
                    Cell cell_6 = ExcelUtil.getCell(row, 11);
                    cell_6.setCellStyle(xssfCellStyle);
                    cell_6.setCellValue(outerDesignChangePrice.getCheckPrice());
                    rowNum++;
                }
            } else {
                CellRangeAddress cellRangeAddress_1 = new CellRangeAddress(rowNum, rowNum, 1, 2);
                ExcelUtil.setCellRangeBorderThin(sheet, cellRangeAddress_1);
                sheet.addMergedRegion(cellRangeAddress_1);
                CellRangeAddress cellRangeAddress_3 = new CellRangeAddress(rowNum, rowNum, 4, 7);
                ExcelUtil.setCellRangeBorderThin(sheet, cellRangeAddress_3);
                sheet.addMergedRegion(cellRangeAddress_3);
                CellRangeAddress cellRangeAddress_5 = new CellRangeAddress(rowNum, rowNum, 9, 10);
                ExcelUtil.setCellRangeBorderThin(sheet, cellRangeAddress_5);
                sheet.addMergedRegion(cellRangeAddress_5);
                Row row = ExcelUtil.getRow(sheet, rowNum);
                row.setHeightInPoints(20);
                InnerDesignChangePrice outerDesignChangePrice = outerDesignChangePricesList.get(0);
                Cell cell_0 = ExcelUtil.getCell(row, 0);
                cell_0.setCellStyle(xssfCellStyle);
                cell_0.setCellValue(type);
                Cell cell_1 = ExcelUtil.getCell(row, 1);
                cell_1.setCellStyle(xssfCellStyle);
                cell_1.setCellValue(outerDesignChangePrice.getName());
                Cell cell_2 = ExcelUtil.getCell(row, 3);
                cell_2.setCellStyle(xssfCellStyle);
                cell_2.setCellValue(outerDesignChangePrice.getPrice());
                Cell cell_3 = ExcelUtil.getCell(row, 4);
                cell_3.setCellStyle(xssfCellStyle);
                cell_3.setCellValue(outerDesignChangePrice.getNum());
                Cell cell_4 = ExcelUtil.getCell(row, 8);
                cell_4.setCellStyle(xssfCellStyle);
                cell_4.setCellValue(outerDesignChangePrice.getTotalPrice());
                Cell cell_5 = ExcelUtil.getCell(row, 9);
                cell_5.setCellStyle(xssfCellStyle);
                cell_5.setCellValue(designFeeTotal);
                Cell cell_6 = ExcelUtil.getCell(row, 11);
                cell_6.setCellStyle(xssfCellStyle);
                cell_6.setCellValue(outerDesignChangePrice.getCheckPrice());
                rowNum++;
            }
        }
        return rowNum;
    }

    private int exportInnerDesignChangePriceExcel2(XSSFSheet sheet, XSSFCellStyle xssfCellStyle, int rowNum, Map<String, List<InnerDesignChangePrice>> typeMap, String type, InnerDesignChangesDetail outerDesignChangesDetail) {
        if (typeMap.containsKey(type)) {
            List<InnerDesignChangePrice> outerDesignChangePricesList = typeMap.get(type);
            int size = outerDesignChangePricesList.size();
            CellRangeAddress typeCellRangeAddress = new CellRangeAddress(rowNum, rowNum + size, 0, 0);
            ExcelUtil.setCellRangeBorderThin(sheet, typeCellRangeAddress);
            sheet.addMergedRegion(typeCellRangeAddress);
            CellRangeAddress sizeCellRangeAddress = new CellRangeAddress(rowNum, rowNum, 4, 6);
            ExcelUtil.setCellRangeBorderThin(sheet, sizeCellRangeAddress);
            sheet.addMergedRegion(sizeCellRangeAddress);
            CellRangeAddress subtotalCellRangeAddress0 = new CellRangeAddress(rowNum, rowNum, 9, 10);
            ExcelUtil.setCellRangeBorderThin(sheet, subtotalCellRangeAddress0);
            sheet.addMergedRegion(subtotalCellRangeAddress0);
            Row firstRow = ExcelUtil.getRow(sheet, rowNum);
            Cell cell_0_0 = ExcelUtil.getCell(firstRow, 0);
            cell_0_0.setCellStyle(xssfCellStyle);
            cell_0_0.setCellValue(type);
            Cell cell_0_1 = ExcelUtil.getCell(firstRow, 1);
            cell_0_1.setCellStyle(xssfCellStyle);
            cell_0_1.setCellValue("名称");
            Cell cell_0_2 = ExcelUtil.getCell(firstRow, 2);
            cell_0_2.setCellStyle(xssfCellStyle);
            cell_0_2.setCellValue("牌号");
            Cell cell_0_3 = ExcelUtil.getCell(firstRow, 3);
            cell_0_3.setCellStyle(xssfCellStyle);
            cell_0_3.setCellValue("单价（元）");
            Cell cell_0_4 = ExcelUtil.getCell(firstRow, 4);
            cell_0_4.setCellStyle(xssfCellStyle);
            cell_0_4.setCellValue("规格mm");
            Cell cell_0_5 = ExcelUtil.getCell(firstRow, 7);
            cell_0_5.setCellStyle(xssfCellStyle);
            cell_0_5.setCellValue("重量kg/数量");
            Cell cell_0_6 = ExcelUtil.getCell(firstRow, 8);
            cell_0_6.setCellStyle(xssfCellStyle);
            cell_0_6.setCellValue("金额（元）");
            Cell cell_0_7 = ExcelUtil.getCell(firstRow, 9);
            cell_0_7.setCellStyle(xssfCellStyle);
            Cell cell_0_8 = ExcelUtil.getCell(firstRow, 11);
            cell_0_8.setCellStyle(xssfCellStyle);
            cell_0_8.setCellValue(outerDesignChangesDetail.getMainFeeCheck());
            String designFeeTotal = outerDesignChangesDetail.getMaterialFeeTotal();
            rowNum++;
            if (size > 1) {
                CellRangeAddress subtotalCellRangeAddress = new CellRangeAddress(rowNum, rowNum + size - 1, 9, 10);
                ExcelUtil.setCellRangeBorderThin(sheet, subtotalCellRangeAddress);
                sheet.addMergedRegion(subtotalCellRangeAddress);
                Row secondRow = ExcelUtil.getRow(sheet, rowNum);
                Cell cell_1_9 = ExcelUtil.getCell(secondRow, 9);
                cell_1_9.setCellStyle(xssfCellStyle);
                cell_1_9.setCellValue(designFeeTotal);
                for (int i = 0; i < size; i++) {
                    Row row = ExcelUtil.getRow(sheet, rowNum);
                    row.setHeightInPoints(20);
                    InnerDesignChangePrice outerDesignChangePrice = outerDesignChangePricesList.get(i);
                    Cell cell_1 = ExcelUtil.getCell(row, 1);
                    cell_1.setCellStyle(xssfCellStyle);
                    cell_1.setCellValue(outerDesignChangePrice.getName());
                    Cell cell_2 = ExcelUtil.getCell(row, 2);
                    cell_2.setCellStyle(xssfCellStyle);
                    cell_2.setCellValue(outerDesignChangePrice.getSpecification());
                    Cell cell_3 = ExcelUtil.getCell(row, 3);
                    cell_3.setCellStyle(xssfCellStyle);
                    cell_3.setCellValue(outerDesignChangePrice.getPrice());
                    Cell cell_4 = ExcelUtil.getCell(row, 4);
                    cell_4.setCellStyle(xssfCellStyle);
                    cell_4.setCellValue(outerDesignChangePrice.getLength());
                    Cell cell_5 = ExcelUtil.getCell(row, 5);
                    cell_5.setCellStyle(xssfCellStyle);
                    cell_5.setCellValue(outerDesignChangePrice.getWidth());
                    Cell cell_6 = ExcelUtil.getCell(row, 6);
                    cell_6.setCellStyle(xssfCellStyle);
                    cell_6.setCellValue(outerDesignChangePrice.getHeight());
                    Cell cell_7 = ExcelUtil.getCell(row, 7);
                    cell_7.setCellStyle(xssfCellStyle);
                    cell_7.setCellValue(outerDesignChangePrice.getNum());
                    Cell cell_8 = ExcelUtil.getCell(row, 8);
                    cell_8.setCellStyle(xssfCellStyle);
                    cell_8.setCellValue(outerDesignChangePrice.getTotalPrice());
                    Cell cell_10 = ExcelUtil.getCell(row, 11);
                    cell_10.setCellStyle(xssfCellStyle);
                    cell_10.setCellValue(outerDesignChangePrice.getCheckPrice());
                    rowNum++;
                }
            } else {
                Row row = ExcelUtil.getRow(sheet, rowNum);
                row.setHeightInPoints(20);
                InnerDesignChangePrice outerDesignChangePrice = outerDesignChangePricesList.get(0);
                Cell cell_1 = ExcelUtil.getCell(row, 1);
                cell_1.setCellStyle(xssfCellStyle);
                cell_1.setCellValue(outerDesignChangePrice.getName());
                Cell cell_2 = ExcelUtil.getCell(row, 2);
                cell_2.setCellStyle(xssfCellStyle);
                cell_2.setCellValue(outerDesignChangePrice.getSpecification());
                Cell cell_3 = ExcelUtil.getCell(row, 3);
                cell_3.setCellStyle(xssfCellStyle);
                cell_3.setCellValue(outerDesignChangePrice.getPrice());
                Cell cell_4 = ExcelUtil.getCell(row, 4);
                cell_4.setCellStyle(xssfCellStyle);
                cell_4.setCellValue(outerDesignChangePrice.getLength());
                Cell cell_5 = ExcelUtil.getCell(row, 5);
                cell_5.setCellStyle(xssfCellStyle);
                cell_5.setCellValue(outerDesignChangePrice.getWidth());
                Cell cell_6 = ExcelUtil.getCell(row, 6);
                cell_6.setCellStyle(xssfCellStyle);
                cell_6.setCellValue(outerDesignChangePrice.getHeight());
                Cell cell_7 = ExcelUtil.getCell(row, 7);
                cell_7.setCellStyle(xssfCellStyle);
                cell_7.setCellValue(outerDesignChangePrice.getNum());
                Cell cell_8 = ExcelUtil.getCell(row, 8);
                cell_8.setCellStyle(xssfCellStyle);
                cell_8.setCellValue(outerDesignChangePrice.getTotalPrice());
                Cell cell_10 = ExcelUtil.getCell(row, 11);
                cell_10.setCellStyle(xssfCellStyle);
                cell_10.setCellValue(outerDesignChangePrice.getCheckPrice());
                rowNum++;
            }
        }
        return rowNum;
    }

    private int exportInnerDesignChangePriceExcel3(XSSFSheet sheet, XSSFCellStyle xssfCellStyle, int rowNum, Map<String, List<InnerDesignChangePrice>> typeMap, String type, InnerDesignChangesDetail outerDesignChangesDetail) {
        if (typeMap.containsKey(type)) {
            List<InnerDesignChangePrice> outerDesignChangePricesList = typeMap.get(type);
            int size = outerDesignChangePricesList.size();
            CellRangeAddress typeCellRangeAddress = new CellRangeAddress(rowNum, rowNum + size, 0, 0);
            ExcelUtil.setCellRangeBorderThin(sheet, typeCellRangeAddress);
            sheet.addMergedRegion(typeCellRangeAddress);
            CellRangeAddress sizeCellRangeAddress = new CellRangeAddress(rowNum, rowNum, 3, 8);
            ExcelUtil.setCellRangeBorderThin(sheet, sizeCellRangeAddress);
            sheet.addMergedRegion(sizeCellRangeAddress);
            CellRangeAddress subtotalCellRangeAddress0 = new CellRangeAddress(rowNum, rowNum, 9, 10);
            ExcelUtil.setCellRangeBorderThin(sheet, subtotalCellRangeAddress0);
            sheet.addMergedRegion(subtotalCellRangeAddress0);
            Row firstRow = ExcelUtil.getRow(sheet, rowNum);
            firstRow.setHeightInPoints(20);
            Cell cell_0_0 = ExcelUtil.getCell(firstRow, 0);
            cell_0_0.setCellStyle(xssfCellStyle);
            cell_0_0.setCellValue(type);
            Cell cell_0_1 = ExcelUtil.getCell(firstRow, 1);
            cell_0_1.setCellStyle(xssfCellStyle);
            cell_0_1.setCellValue("科目");
            Cell cell_0_2 = ExcelUtil.getCell(firstRow, 2);
            cell_0_2.setCellStyle(xssfCellStyle);
            cell_0_2.setCellValue("比例");
            Cell cell_0_3 = ExcelUtil.getCell(firstRow, 3);
            cell_0_3.setCellStyle(xssfCellStyle);
            cell_0_3.setCellValue("金额（元）");
            Cell cell_0_7 = ExcelUtil.getCell(firstRow, 9);
            cell_0_7.setCellStyle(xssfCellStyle);
            Cell cell_0_8 = ExcelUtil.getCell(firstRow, 11);
            cell_0_8.setCellStyle(xssfCellStyle);
            cell_0_8.setCellValue(outerDesignChangesDetail.getMaterialFeeCheck());
            String designFeeTotal = outerDesignChangesDetail.getOtherFeeTotal();
            rowNum++;
            if (size > 1) {
                CellRangeAddress subtotalCellRangeAddress = new CellRangeAddress(rowNum, rowNum + size - 1, 9, 10);
                ExcelUtil.setCellRangeBorderThin(sheet, subtotalCellRangeAddress);
                sheet.addMergedRegion(subtotalCellRangeAddress);
                Row secondRow = ExcelUtil.getRow(sheet, rowNum);
                Cell cell_1_9 = ExcelUtil.getCell(secondRow, 9);
                cell_1_9.setCellStyle(xssfCellStyle);
                cell_1_9.setCellValue(designFeeTotal);
                for (int i = 0; i < size; i++) {
                    CellRangeAddress totalPriceCellRangeAddress = new CellRangeAddress(rowNum, rowNum, 3, 8);
                    ExcelUtil.setCellRangeBorderThin(sheet, totalPriceCellRangeAddress);
                    sheet.addMergedRegion(totalPriceCellRangeAddress);
                    Row row = ExcelUtil.getRow(sheet, rowNum);
                    row.setHeightInPoints(20);
                    InnerDesignChangePrice outerDesignChangePrice = outerDesignChangePricesList.get(i);
                    Cell cell_1 = ExcelUtil.getCell(row, 1);
                    cell_1.setCellStyle(xssfCellStyle);
                    cell_1.setCellValue(outerDesignChangePrice.getName());
                    Cell cell_2 = ExcelUtil.getCell(row, 2);
                    cell_2.setCellStyle(xssfCellStyle);
                    cell_2.setCellValue(outerDesignChangePrice.getNum());
                    Cell cell_3 = ExcelUtil.getCell(row, 3);
                    cell_3.setCellStyle(xssfCellStyle);
                    cell_3.setCellValue(outerDesignChangePrice.getTotalPrice());
                    Cell cell_10 = ExcelUtil.getCell(row, 11);
                    cell_10.setCellStyle(xssfCellStyle);
                    cell_10.setCellValue(outerDesignChangePrice.getCheckPrice());
                    rowNum++;
                }
            } else {
                CellRangeAddress totalPriceCellRangeAddress = new CellRangeAddress(rowNum, rowNum, 3, 8);
                ExcelUtil.setCellRangeBorderThin(sheet, totalPriceCellRangeAddress);
                sheet.addMergedRegion(totalPriceCellRangeAddress);
                Row row = ExcelUtil.getRow(sheet, rowNum);
                row.setHeightInPoints(20);
                InnerDesignChangePrice outerDesignChangePrice = outerDesignChangePricesList.get(0);
                Cell cell_1 = ExcelUtil.getCell(row, 1);
                cell_1.setCellStyle(xssfCellStyle);
                cell_1.setCellValue(outerDesignChangePrice.getName());
                Cell cell_2 = ExcelUtil.getCell(row, 2);
                cell_2.setCellStyle(xssfCellStyle);
                cell_2.setCellValue(outerDesignChangePrice.getNum());
                Cell cell_3 = ExcelUtil.getCell(row, 3);
                cell_3.setCellStyle(xssfCellStyle);
                cell_3.setCellValue(outerDesignChangePrice.getTotalPrice());
                Cell cell_10 = ExcelUtil.getCell(row, 11);
                cell_10.setCellStyle(xssfCellStyle);
                cell_10.setCellValue(outerDesignChangePrice.getCheckPrice());
                rowNum++;
            }
        }
        return rowNum;
    }

}
